我已尝试通过以下方式实现这一点:
from tkinter import*
# creates a GUI
Tester = Tk()
# gives the mainframe a title
Tester.title("")
NonEssentialFoodEntry = Entry(Tester, width="30")
NonEssentialFoodEntry.place(x=300,y=540)
NonEssentialFood = ""
NonEssentialFood = NonEssentialFoodEntry.get()
NonEssentialFood = int(NonEssentialFood)
def checker():
if NonEssentialFood <0:
print(' negative number entered')
# assigns attributes to button
Checker=Button(Tester, height="7",width="30",font=300,command=checker)
# displays and places button
Checker.place(x=700, y=580)
NonEssentialFood = int(NonEssentialFood)
ValueError: invalid literal for int() with base 10: ''
>>>
我认为可能有一种特殊的方法可以将条目小部件的内容转换为整数,但我不知道为什么(条目小部件的内容默认为字符串)
例如,您应该仅在用户按下按钮时转换条目的内容
相关问题 更多 >
编程相关推荐