###質問
python3でTkinterを利用したBMI計算機を作っているのですが、入力された文字列を取得する方法がわかりません。 どなたかご教授願えませんでしょうか。 当方初心者のため非常に見づらいコードですが、よろしくお願いします。
###発生している問題・エラーメッセージ
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 1550, in __call__ return self.func(*args) File "C:\Program Files\Python35\SOURCE_CODE\tk\BMI.py", line 5, in tehutehuapple Wei = weiBox.get() AttributeError: 'NoneType' object has no attribute 'get'
###該当のソースコード
from tkinter import Tk, ttk, font, sys, messagebox def tehutehuapple(): Wei = float(weiBox.get()) Hei = float(heiBox.get()) result = Wei / (Hei*Hei) BMIresult = ttk.Label(root, text=result) BMIresult = BMIresult.place(x=120, y=250) return root = Tk() root.geometry("360x360") root.resizable(0,0) root.title("BMIを計算してしまったのですが!") root.iconbitmap("tehu.ico") font = font.Font(family='MS ゴシック', size=24) weight = ttk.Label(root, text='体重:', font=font) weight = weight.place(x=30, y=60) height = ttk.Label(root, text='身長:', font=font) height = height.place(x=30, y=150) BMI = ttk.Label(root, text='BMI:', font=font) BMI = BMI.place(x=35, y=250) calc = ttk.Button(root, text='計算!', command = tehutehuapple) calc = calc.place(x=145, y=200) end = ttk.Button(root, text='終了', command = sys.exit) end = end.place(x=145, y=330) weiBox = ttk.Entry() weiBox = weiBox.place(x=120, y=70) heiBox = ttk.Entry() heiBox = heiBox.place(x=120, y=160) root.mainloop()
###補足情報(言語/FW/ツール等のバージョンなど)
Python 3.5.2
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/15 07:24