from tkinter import * from tkinter.ttk import * class MyButtonGUI: '''A tkinter program using classes rather than global variables.''' def __init__(self, window): self.button_text = StringVar() self.button_text.set('Hello') button = Button(window, textvariable=self.button_text, command=self.my_button_behavior) button.grid(row=0, column=0) button.configure(padding=50) def my_button_behavior(self): '''executes when the 'hello' button is clicked''' self.button_text.set('You clicked me!') def main(): window = Tk() # create the main program window MyButtonGUI(window) # create the button window.mainloop() # enter the GUI main loop main()