i am having issue with the tkinter StrinVar() and i dont have much knowledge in tkinter and would like some help, thanks.
What i have done is i created two window in which each has a Entry widget and Button widget if you click button of one window then that window gets withdraw and another window pop ups and if you click button in that pop up window then it withdraws and a original window gets pop up.Here is the code:-
from tkinter import *
def x():
a1.set("")
a.withdraw()
b.deiconify()
def y():
b1.set("")
b.withdraw()
a.deiconify()
a=Tk()
a.withdraw()
a1=StringVar()
b1=StringVar()
Entry(a,textvariable=a1).pack()
Button(a,text="button1",command=x).pack()
a.withdraw()
b=Tk()
Entry(b,textvariable=b1).pack()
Button(b,text="button2",command=y).pack()
mainloop()
if you write something in entry widget and press button2 then second window pop ups then again if you write something in entry widget and press button1 the entry field is not getting updated in previous first window.
i found that someone suggested that there should not be two instanses of Tk()
a tkinter must have only one instanse of Tk()
for multiple window use Toplevel()
. So, i changed b=Tk()
to b=Toplevel()
which works fine and StringVar()
was updating value
Now, my question is that 1)What is the reason/logic behind not updating StingVar()
with two instanses of Tk()
2) is there any way to make StringVar()
to update value with having two instanses of Tk()