将事件绑定到窗口小部件

问题描述 投票:0回答:1

我需要将按钮小部件绑定到if语句并将相应的print语句返回到屏幕(在结果标签内)这里是我写的代码:

from  tkinter import*
from functools import partial 
def call_result(event):
    temp=numberInput.get()
    if temp >22:
        print ("Increase")
    elif temp ==22:
        print ("reduce")
    else:
        print ("done")
        rLabel1.config(text="%d" %d)
    return

root=Tk()
numberInput=IntVar()
label_1= Label(root,text="Enter Temperature",fg="blue")
label_1.grid(row=0)
Temperature = Entry(root,bd=5)
Temperature.grid(row=0,column=1)
rLabel1= Label(root,text="Result",fg="blue")
rLabel1.grid(row=1, sticky=W)
call_out=partial(call_result,rLabel1,numberInput)
Button_1 = Button(root, text="OK", command=call_result)
Button_1.grid(row=0,column=2,columnspan=2)
root.mainloop()

请指正,谢谢。

python user-interface tkinter
1个回答
1
投票

我不是魔术师,但我很确定(event)不是因为tkinter制作的'小部件'所做的命令。所以从(event)中删除def call_result(event):,它应该像我尝试时一样完美。

© www.soinside.com 2019 - 2024. All rights reserved.