pythonpython-3.xtkintertkinter-buttontkinter-label

Binding button to label widget


Trying to call hii function in python tkinter, but nothing happens.

My Code:-

def hii():
    print("hii")


m_root = Tk()
m_frame = Frame(m_root)
m_display = Label(m_frame)

label = Label(m_root,text="hii") #set your text
label.bind("<Enter>",hii)
label.pack()

m_display.pack()
m_frame.pack()
m_display.update()

m_root.mainloop()

Solution

  • First line should be: def hii(event): and it works fine. The function should expect an event as an argument.