import Tkinter
import tkMessageBox
class MyApp(object):
def __init__(self):
self.topFrame = Tkinter.Frame()
self.root = Tk()
self.root.wm_title("My first window!")
self.label = Label(self.root, text="Enter your weight")
self.label.pack(padx=20,pady=10)
self.labeltext = StringVar()
self.labeltext.set("Enter your height!")
Label(self.root, textvariable=self.labeltext).pack()
self.entrytext2 = StringVar()
Entry(self.root, textvariable=self.entrytext2).pack()
self.entrytext2.trace('w', self.entry_changed)
self.buttontext = StringVar()
self.buttontext.set("Bouton")
Button(self.root, textvariable=self.buttontext, command=self.clicked1).pack()
self.entrytext = StringVar()
Entry(self.root, textvariable=self.entrytext).pack()
self.entrytext.trace('w', self.entry_changed)
def calcBMI(self):
weight = float(self.entrytext2.get())
inches = float(self.entrytext.get())
BMI = (weight * 703)/ inches **2
if BMI > 18.5 and BMI < 25:
self.labeltext.set(BMI)
elif BMI < 18.5:
print ' Your BMI is Underweight ', self.value.set(BMI)
else:
print ' Your BMI is Overweight ', self.value.set(BMI)
def clicked1(self):
response = tkMessageBox.askyesno("Confirm", "You clicked?")
if response:
self.labeltext.set("You've been clicked!")
self.buttontext.set("Butttttttton")
print response
MyApp()
したがって、編集すると次のようになります。
File "window1.py", line 45, in <module>
MyApp()
File "window1.py", line 7, in __init__
self.root = Tk()
NameError: global name 'Tk' is not defined