Yesterday, 08:44 AM
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!
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()