Python Forum

Full Version: Transfer Toplevel window entry to root window entry with TKinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()