Hack Forums
[Python] Tkinter 'textvariable' does not work in a secondary window? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Tkinter 'textvariable' does not work in a secondary window? (/showthread.php?tid=5995250)



Tkinter 'textvariable' does not work in a secondary window? - Avispon99 - Aug 1, 2019

Because when I use textvariable from a secondary window that was called from a command in another window, the value set through .set () is not reflected in the secondary window Label.

Example:

Code
import tkinter as tk

def test():
   ven=tk.Tk()
   v1=tk.StringVar()
   v1.set('TEST')
   print(v1.get())
   tk.Label(ven, textvariable=v1).pack()
   ven.mainloop()

win=tk.Tk()
tk.Button(text='BOTON',command=test).pack()
win.mainloop()

In this case, the 'TEST' message set through v1.set () is not updated in the text variable of the Label that was created in the test() function

Why does this happen?