如果我输入一个整数,我会变得无效。如果它不是数字 0 或更大,我希望它无效。非常感谢任何帮助!
from Tkinter import *
import tkMessageBox
from Tkinter import *
import tkMessageBox
class MyApp(object):
def __init__(self):
self.root = Tk()
self.root.wm_title("Question 7")
self.label = Label(self.root, text="Enter weight in pounds",
font=('Calibri', 50))
self.label.pack(padx=20,pady=10)
self.labeltext = StringVar()
self.labeltext.set("")
Label(self.root, textvariable=self.labeltext).pack()
self.entrytext = StringVar()
Entry(self.root, textvariable=self.entrytext).pack()
self.entrytext.trace('w', self.entry_changed)
self.root.mainloop()
def entry_changed(self, a, b, c):
s = self.entrytext.get()
try:
a=int(s)*4.3
self.labeltext.set(a)