Python Forum
Transfer Toplevel window entry to root window entry with TKinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Transfer Toplevel window entry to root window entry with TKinter (/thread-23940.html)



Transfer Toplevel window entry to root window entry with TKinter - HBH - Jan-23-2020

With Tkinter, on a PopUp Toplevel window with an Entry and Button, when Destroy by the button, I want the TopLevel window Entry to be transferred to my root window entry. The code below transfer the root window entry value to the popup window entry. If the entry of the popup window is changed, how to transfer it to the root window entry?

  1. from tkinter import *
    root = Tk()
    root.geometry("250x100")
    root.title("Root Window")
    
    
    def open_popup(num):
    popup = Toplevel()
    popup.title("PopUp")
    popup.geometry("250x100")
    
    value = Entry(popup)
    value.place(height=25, width=25, x=100, y=10)
    value.insert(0, str(num))
    
    btn_ok = Button(popup, text="Return", command=popup.destroy)
    btn_ok.place(height=30, width=60, x=90, y=45)
    
    
    main_entry = Entry(root)
    main_entry.place(height=25, width=30, x=110, y=10)
    main_entry.insert(0, "111")
    
    button_ok = Button(
    root, text="OK", command=lambda: open_popup(main_entry.get()))
    button_ok.place(height=30, width=30, x=110, y=45)
    
    root.mainloop()