# Click Counter
# Demonstrates binding an event with an event handler
print("Step 0 First line to run")
from tkinter import *
# main
print("Step 1 root =Tk Setup root window")
root = Tk()
print("Step 2 Setup window title : Click Counter")
root.title("Click Counter")
print("Step 3 Setup : Size root.geometry")
root.geometry("200x50")
class Application(Frame):
print("Step 4 Next, Entered the : class Application(Frame):")
print("")
print("This step is not clear to me?")
print(""" Normally would see:
root = Tk() #This would create the base window
frame = Frame(root) #The frame lives in the base window
frame.pack() #Places the frame in the window
BUT we see instead:
root = Tk() #This would create the base window
app = Application(root) #Not sure what is going on with this line?
#If I had to guess app = frame and
#Application=Frame
#Meaning frame and Frame are not keywords
class Application(Frame):#Also not sure with this line?
#Understood creating Class from which
#an instance will be created as an object.
#The use of Frame has me confused?
""")
def __init__(self, master):
print("Step 5 Entered : def __init__(self, master):")
print("Why is .......................^self, master used here?")
print("""Step 6 Next run : super(Application, self).__init__(master) """)
super(Application, self).__init__(master)
self.grid()
print("Step 7 SET : self_bttn_clicks = 0")
self.bttn_clicks = 0
print("Step 8 CALL: self.create_widget()")
self.create_widget()
def update_count(self):
print("Step 9 Entered : def update_count(self):")
print("""Step 10 Increase click count and display new total. """)
self.bttn_clicks += 2
self.bttn["text"] = "Total Clicks: " + str(self.bttn_clicks)
def create_widget(self):
print("Step 11 Entered : def create_widget(self):")
print("""Step 12 Create button which displays number of clicks. """)
self.bttn = Button(self)
self.bttn["text"]= "Total Clicks: 0"
self.bttn["command"] = self.update_count
self.bttn.grid()
app = Application(root)
print("Step 13 root_mainloop")
root.mainloop()
print("Step 14 root_mainloop")
Comments