Coding for Unit 2

Lena Fuller

from Tkinter import *

 

class Application (Frame):

   

   def __init__(self, master):        # Initialization is a constructor method

       Frame.__init__(self,master)  

       self.grid()

       self.button_clicks =0           # For counting number of button clicks

       self.create_widgets()

       

   def create_widgets(self):         # Orders for button

       self.button= Button(self)

       self.button["text"] = "Click here if this changes your view on recycling at SAS"

       self.button["command"] = self.update_count

       self.button.grid()     # Put on grid so it shows up

       

   def update_count(self):   # To increase the count when the button is clicked

       self.button_clicks +=1

       self.button["text"] = "Click here if this changes your view on recycling at SAS" + str(self.button_clicks)

       

root = Tk()         # Line is necessary for buttons to appear

root.title("repsychology")  

root.geometry("200x200") # width by height in a string

 

app = Application(root)

 

root.mainloop()  # In order for button process to repeat