I need to ask the user for an arbitrarily long list of key-folder pairs, so I use
Toplevel to create a popup where i lay out a growable list pairs of custom buttons (one to bind the key and one to select the folder).
I’d then like to wait til the user closes the window and read the status on the widgets, but
wait_window() waits until it’s too late and the widgets are already deconstructed
Is there an easy way to do something like
popup.wait_window() and access the attributes in the widgets?
EDIT: My ideal solution would be a single function like
popup_bindings() that creates the popup and returns the value, so I could assign a variable directly with
bindings = popup_bindings()
EDIT 2: Right now I’m focusing on the popup return value aspect, I will build the actual dialog after I’ve figured that out
I’ve come up with a relatively inelegant solution: I use a list as a mutable “callback” variable that’s preserved when the object is destroyed, and I use the
protocol method to ensure that the value is saved when the window is closed.
import tkinter as tk
self.value = out_value
self.toplevel = tk.Toplevel(parent)
self.entry = tk.Entry(master=self.toplevel)
def show_popup() -> str:
val = 
x = EntryPopup(val,window)
lab["text"] = show_popup()
window = tk.Tk()
lab = tk.Label(text="Your text here")
tk.Button(command=set_label,text="Set label text").pack()
Thank you for sharing this. I’m sure that as I learn and develop my Tk interface skills, your solution will come in handy.
Enjoy your day.