where to put
v = StringVar()
?
You have to store v at a place where you can reach it
- at entry widget instanciation
- at question checker
Possible solutions include
- declare v in upper context, thus you can access it from anywhere
- declare v as an attribute of demo2, pass it as an argument to question_checker (sounds better to me, Demo2 responsability is thus to show and check the answer of a question)
- declare v as an attribute of demo1, pass it as an argument to Demo2 constructor and question_checker
By the way, if you do not make use of the trace functionality (react on each variable change) of StringVar, you can get rid of StringVar
class Demo2:
def __init__(self, master):
#[...]
self.entry = tk.Entry(self.master)
self.entry.pack()
#[...]
def close_windows(self):
#access entry content through
self.entry.get()
Also note that onelining widget creation an geometry in tkinter wrongly initialise your widget variables. It will always contain None
since pack
(and grid
) always return None.