Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class Main(tk.Tk):
- def __init__(self):
- super().__init__()
- self.l = tk.Label(self, text='???')
- self.l.pack()
- b = tk.Button(self, text='New', command=self.on_click)
- b.pack()
- self.mainloop()
- def on_click(self):
- new = Next(self)
- print('close')
- class Next(tk.Toplevel):
- def __init__(self, master): # master - to get access to parent window
- super().__init__(master)
- self.var = tk.StringVar() # tk.StringVar(self)
- e = tk.Entry(self, textvariable=self.var)
- e.pack()
- b = tk.Button(self, text='Close', command=self.on_click)
- b.pack()
- #self.mainloop() # no need it
- def on_click(self):
- print(self.var.get()) # get text from Entry
- self.master.l['text'] = self.var.get() # put in parent window
- self.destroy()
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement