Python Forum
Tkinter: Problem with storing data from one window to the other
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter: Problem with storing data from one window to the other
#1
Dear all,

I am very new to Python and Tkinter, so sorry if the question is very basic.
I cannot manage to store the value of a parameter, here "value" and to print it in a new window.
Please find the code below.
Thanks a lot for your help!

import tkinter as tk

#Initiate the values
#kLa = tk.DoubleVar()


# Create an object "window"
window = tk.Tk()
window.title("Application Test")


window.minsize(400,200)
window.grid_rowconfigure(0, weight=1)
window.grid_rowconfigure(6, weight=1)
window.grid_columnconfigure(0, weight=1)
window.grid_columnconfigure(3, weight=1)

# Function to open a new window
def open_window_value():
    value = float()
    def do_ok(event=None):
        nonlocal value
        value = entryvalue.get()
        window_value.destroy()

    def do_cancel():
        nonlocal value
        value = None
        window_value.destroy()
    window_value = tk.Toplevel(window)  # Create a new window
    window_value.title("Window value")
    window_value.geometry("250x150")  

    labelTitle = tk.Label(window_value, text="This is the window for value")
    labelTitle.grid(row=0,column=0)
    labelvalue = tk.Label(window_value,text = "Enter the value")

    labelvalue.grid(row=1, column=0, columnspan=4)
    entryvalue = tk.Entry(window_value, textvariable = value, width = 30)
    entryvalue.grid(row=2, column=0)
    tk.Button(window_value, text="ok", command=do_ok).grid(row=3, column=0)
    tk.Button(window_value, text="cancel", command=do_cancel).grid(row=3, column=1)
    entryvalue.bind("<Return>", do_ok)
    window_value.wait_window(window_value)
    return value

def open_window_Calc():
    window_Calc = tk.Toplevel(window)  # Create a new window
    window_Calc.title("Window Other Parameters")
    window_Calc.geometry("250x150")  

    tk.Label(window_Calc, text="This is a new window").grid(row=0, column=0)
    tk.Label(window_Calc, text=value).grid(row=1, column=0)
    

zoneMenu = tk.Frame(window, borderwidth=3, bg='#557788')
zoneMenu.grid(row=0,column=0)

menuvalue = tk.Button(zoneMenu, text='value', width='20', borderwidth=2, 
                         bg='gray', activebackground='darkorange',relief = tk.RAISED, command = open_window_value)


menuvalue.grid(row=0,column=0)

Calculation = tk.Button(zoneMenu, text='Calculate!', width='20', borderwidth=2, 
                        bg='gray', activebackground='darkorange',relief = tk.RAISED, command = open_window_Calc)

Calculation.grid(row=1,column=1)


def quit():
    window.destroy()
    
window.protocol('WM_DELETE_WINDOW', quit)

# Start the tkinter loop (to be put at the end)
window.mainloop()
Reply


Messages In This Thread
Tkinter: Problem with storing data from one window to the other - by iforire - May-11-2025, 08:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter only storing last element/data from entry widget bertschj1 8 770 May-06-2025, 11:54 PM
Last Post: deanhystad
  LLM data I/O - for storing notes Alkanet 0 422 Dec-19-2024, 09:08 AM
Last Post: Alkanet
  Unique Tkinter Window kucingkembar 11 2,486 Aug-11-2024, 01:49 PM
Last Post: deanhystad
  Storing data in readable place user_404_lost_and_found 4 1,556 Jul-22-2024, 06:14 AM
Last Post: Pedroski55
  tkinter photo image problem jacksfrustration 5 3,897 Jun-27-2024, 12:06 AM
Last Post: AdamHensley
  add entries and labels to the window tkinter jacksfrustration 3 2,556 Oct-10-2023, 06:41 PM
Last Post: buran
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 5,864 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 3,525 Sep-01-2023, 12:07 AM
Last Post: lunacy90
Bug tkinter.TclError: bad window path name "!button" V1ber 2 2,446 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 2,047 Jun-13-2022, 08:59 AM
Last Post: Shena76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020