ich verstehe nicht, weshalb im zweiten Fenster der tk.StringVar() nicht angezeigt wird.
Code: Alles auswählen
import Tkinter as tk
class Benutzer():
def __init__(self):
self.second = tk.Tk()
self.second.title("Second window")
self.second.geometry("%dx%d+%d+%d" % (200, 100, 600, 250))
self.var = tk.StringVar()
self.var.set("hallo")
self.label = tk.Label(self.second, textvariable=self.var)
self.label.place(relx=.2, rely=.2, anchor="w")
self.start_button = tk.Button(self.second, text="CLOSE", width=15, command=self.close)
self.start_button.place(relx=.2, rely=.5, anchor="w")
def close(self):
self.second.destroy()
class MyFirstGUI:
def __init__(self):
self.first = tk.Tk()
self.first.title("First window")
self.first.geometry("%dx%d+%d+%d" % (200, 100, 600, 250))
self.label = tk.Label(self.first, text="This is my first GUI!")
self.label.place(relx=.2, rely=.2, anchor="w")
self.start_button = tk.Button(self.first, text="START", width=15, command=self.start)
self.start_button.place(relx=.2, rely=.5, anchor="w")
self.start_button = tk.Button(self.first, text="CLOSE", width=15, command=self.close)
self.start_button.place(relx=.2, rely=.8, anchor="w")
self.first.mainloop()
def start(self):
self.first.withdraw()
self.first.update_idletasks()
benutzer_thread = Benutzer()
print ("Finished!")
def close(self):
self.first.destroy()
MyFirstGUI()