将事件绑定到小部件

2024-06-26 14:10:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要将button小部件绑定到if语句,并将相应的print语句返回到屏幕(在result标签内) 下面是我写的代码:

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()

请纠正我谢谢


Tags: textfromifbuttonroot语句resultcall
1条回答
网友
1楼 · 发布于 2024-06-26 14:10:19

我不是魔术师,但我很肯定(event)不是由tkinter制作的“widgets”完成的命令。所以从def call_result(event):中删除(event),它应该可以像我尝试的那样完美地工作

相关问题 更多 >