from tkinter import * class EntryStringVarDemo: def __init__(self, rootWin): self.button = Button(rootWin,text="enter", command=self.clicked) self.button.pack() #A StringVar is a special object that holds strings and #can be linked to a GUI element such as an Entry. # 1) MAGIC HERE self.magicEntryVar = StringVar() # 2) Create Entry widget setting magic textvariable! self.entry = Entry(rootWin,textvariable=self.magicEntryVar) # don't need delete and add text in the Entry widget # self.entry.delete(0,END) # self.entry.insert(0,"type your name here") self.magicEntryVar.set("nice magic!") self.entry.pack() self.ourRoot = rootWin def clicked(self): print("Button was clicked!") # get text from the Entry widget # eText = self.entry.get() #3) Simple to get the text from the entry eText = self.magicEntryVar.get() print(eText) #4) So easy to set the text for the entry self.magicEntryVar.set("wow. indeed.") # Create the main root window, instantiate the object, and run main loop! rootWin = Tk() app = EntryStringVarDemo(rootWin) rootWin.mainloop()