Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何才能从Python GUI中的用户输入中不获得以10为基数的错误?_Python_User Interface - Fatal编程技术网

如何才能从Python GUI中的用户输入中不获得以10为基数的错误?

如何才能从Python GUI中的用户输入中不获得以10为基数的错误?,python,user-interface,Python,User Interface,我正在尝试使用GUI和Python来创建一个带有整数输入的简单函数 我对GUI概念非常陌生,所以我不知道还能做什么 from tkinter import * root = Tk() peopleText = Label(root, text="How many people are in your household? ") wageText = Label(root, text="How much do you make a month before deductions? ") pe

我正在尝试使用GUI和Python来创建一个带有整数输入的简单函数

我对GUI概念非常陌生,所以我不知道还能做什么

from tkinter import *

root = Tk()

peopleText = Label(root, text="How many people are in your household? ")
wageText = Label(root, text="How much do you make a month before deductions? ")

peopleInput = Entry(root)
wageInput = Entry(root)

runButton = Button(root, text="Run")

peopleText.grid(row=1, column=0)
wageText.grid(row=2, column=0)
peopleInput.grid(row=1, column=1)
wageInput.grid(row=2, column=1)

def runProcess():
    incomeSNAP = int(peopleInput.get()) - 1
    incomeHousing = int(peopleInput.get()) - 1
    if int(wageInput.get()) <= incomeSNAP:
        print("Yes")
    else:
        print("No")
    if int(wageInput.get()) <= incomeHousing:
        print("Yes")
    else:
        print("No")

runButton = Button(root, text="Run")
runButton.bind('<Button_1>', runProcess())
runButton.pack()

root.mainloop()

如果您注释掉代码中的
''和.pack()
,然后将
command=runProcess
添加到应该运行的按钮,则会发现问题

从tkinter导入*
root=Tk()
peopleText=Label(root,text=“你家有多少人?”)
wageText=Label(root,text=“扣除前一个月你挣多少钱?”)
peopleInput=条目(根)
输入=输入(根)
runButton=按钮(root,text=“Run”)
peopleText.grid(行=1,列=0)
wageText.grid(行=2,列=0)
peopleInput.grid(行=1,列=1)
wageInput.grid(行=2,列=1)
def runProcess():
incomeSNAP=int(peopleInput.get())-1
incomeHousing=int(peopleInput.get())-1

如果int(wageInput.get())可能重复,则仍有许多问题需要处理,但对于特定的错误,您需要删除
runButton.bind(“”,runProcess())
上的
()
,因为您需要提供函数的引用。传递
runProcesss()
将立即执行该函数。此外,它应该是
。您要查找的神奇关键字是
try
除了
  File "/Users/noahpark/PycharmProjects/pythonProject/gui.py", line 21, in runProcess
    incomeSNAP = int(peopleInput.get()) - 1
ValueError: invalid literal for int() with base 10: ''