Tkinter, Trouble with Message,Label widget

Ioannis Lalopoulos isgrey at gmail.com
Sun May 3 23:47:20 EDT 2009


I assume that you create the two windows through two different calls
to Tkinter.Tk() but you cannot enter two mainloops (at least not in a
normal way).

If you want a second window use the Toplevel widget.

Try the following, it does what you want:

import Tkinter

root = Tkinter.Tk()

my_text = Tkinter.StringVar(root)

another_window = Tkinter.Toplevel()

entry = Tkinter.Entry(root, textvar=my_text)
entry.pack()

label = Tkinter.Label(another_window, textvar=my_text)
label.pack()

root.mainloop()

In the above example, whatever you type in the entry widget in the
root window gets reflected in the label widget which is inside the
second window, the one that was created with Tkinter.Toplevel().

Hope it helps,

John



More information about the Python-list mailing list