Mercy Ocheche
Mercy Ocheche

Reputation: 1

binding events to widgets

I need to bind the button widget to the if statement and return the corresponding print statement to the screen (inside the result label) here is the code I wrote:

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

Please correct me thanks.

Upvotes: 0

Views: 71

Answers (1)

Jake
Jake

Reputation: 882

I'm no magician but I'm pretty sure (event) isn't for commands done by tkinter made 'widgets'. So remove (event) from def call_result(event): and it should work perfectly as it did when I tried.

Upvotes: 1

Related Questions