Binding an event with an event handler : Event « GUI Tk « Python






Binding an event with an event handler

Binding an event with an event handler
 
from Tkinter import *

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.bttn_clicks = 0    
        self.create_widget()

    def create_widget(self):
        self.bttn = Button(self)
        self.bttn["text"]= "Total Clicks: 0"
        self.bttn["command"] = self.update_count
        self.bttn.grid()

    def update_count(self):
        self.bttn_clicks += 1
        self.bttn["text"] = "Total Clicks: " + str(self.bttn_clicks)
          
root = Tk()
root.geometry("200x50")
app = Application(root)
root.mainloop()

           
         
  








Related examples in the same category

1.Associating arguments to an event-handler functionAssociating arguments to an event-handler function
2.Sharing Information Between Event-Handler FunctionsSharing Information Between Event-Handler Functions
3.What Events Does 'Command' Bind To?What Events Does 'Command' Bind To?
4.adds callbacks function to a buttonadds callbacks function to a button
5.Add system exit action to a buttonAdd system exit action to a button
6.Update Label in action event
7.Class wrapper for GUI
8.Use lambda to generate a call back function for a buttonUse lambda to generate a call back function for a button