Advertisement
Ruddog

Commenting Counter steps

May 10th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. # Click Counter
  2. # Demonstrates binding an event with an event handler
  3. print("Step 0 First line to run")
  4. from tkinter import *
  5. # main
  6. print("Step 1 root =Tk Setup root window")        
  7. root = Tk()
  8. print("Step 2 Setup window title : Click Counter")
  9. root.title("Click Counter")
  10. print("Step 3 Setup : Size root.geometry")
  11. root.geometry("200x50")
  12.  
  13.  
  14.  
  15. class Application(Frame):
  16.     print("Step 4 Next, Entered the : class Application(Frame):")
  17.     print("")
  18.     print("This step is not clear to me?")
  19.     print(""" Normally would see:
  20.        root = Tk()              #This would create the base window
  21.        frame = Frame(root)      #The frame lives in the base window
  22.        frame.pack()             #Places the frame in the window
  23.        BUT we see instead:
  24.        root = Tk()              #This would create the base window
  25.        app = Application(root)  #Not sure what is going on with this line?
  26.                                 #If I had to guess app = frame and
  27.                                 #Application=Frame
  28.                                 #Meaning frame and Frame are not keywords
  29.        class Application(Frame):#Also not sure with this line?
  30.                                 #Understood creating Class from which
  31.                                 #an instance will be created as an object.
  32.                                 #The use of Frame has me confused?
  33.         """)
  34.     def __init__(self, master):
  35.         print("Step 5 Entered : def __init__(self, master):")
  36.         print("Why is .......................^self, master used here?")
  37.         print("""Step 6 Next run : super(Application, self).__init__(master) """)
  38.         super(Application, self).__init__(master)
  39.         self.grid()
  40.         print("Step 7 SET : self_bttn_clicks = 0")
  41.         self.bttn_clicks = 0
  42.         print("Step 8 CALL: self.create_widget()")
  43.         self.create_widget()
  44.    
  45.    
  46.     def update_count(self):
  47.         print("Step 9 Entered : def update_count(self):")
  48.         print("""Step 10 Increase click count and display new total. """)
  49.         self.bttn_clicks += 2
  50.         self.bttn["text"] = "Total Clicks: " + str(self.bttn_clicks)
  51.    
  52.    
  53.     def create_widget(self):
  54.         print("Step 11 Entered : def create_widget(self):")
  55.         print("""Step 12 Create button which displays number of clicks. """)
  56.         self.bttn = Button(self)
  57.         self.bttn["text"]= "Total Clicks: 0"
  58.         self.bttn["command"] = self.update_count
  59.         self.bttn.grid()
  60.  
  61. app = Application(root)
  62. print("Step 13 root_mainloop")
  63.  
  64. root.mainloop()
  65. print("Step 14 root_mainloop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement