Python tkinter get() from another function
GUI programming is usually done inside a class:
class SimpleApp(object): def createGUI(self): ... self.txtName=Entry(sideframe) self.txtName.grid(row=0,column=1) def create(self): ... name=self.txtName.get()
By making txtName
an attribute of self
, you can access its value in other methods with self.txtName
. The other variables can be handled the same way.
It is useful to give your Entry widgets a StringVar instance to store input.
self.myStringVar = tk.StringVar() self.myEntryWidget = tk.Entry(self.myFrame,textvariable=self.myStringVar) self.myEntryWidget.grid(row=1,column=1)
Then in some other function you call:
self.myStringVar.get()
This is all better off inside a class as it makes the GUI much easier to manage.