#stringvar_example.py from tkinter import * class StringVarDemo: def __init__(self, rootWin): #A StringVar is a special object that holds strings and #can be linked to a GUI element such as an Entry. self.sv = StringVar() #Create a entry and button to put in the root window! self.entry = Entry(rootWin, textvariable=self.sv) self.entry.pack() #Add some text: self.sv.set("Here is some text!") self.button = Button(rootWin, text="Click Me!", command=self.clicked) self.button.pack() def clicked(self): print("Button was clicked!") eText = self.sv.get() print("The Entry had the following text in it:", eText) self.sv.set("You clicked!") #Create the main root window, instantiate the object, and run the main loop! rootWin = Tk() app = StringVarDemo( rootWin ) rootWin.mainloop()