The code below is meant to ask for a file name with filedialog
with a hidden root window, after which the root reappears and shows a label that has the selected filename. However, on MacOS 14.5 and Python 3.9.6, the deiconify
does not make the window reappear. I have to click on the Python icon in the dock in order for the window to appear. If I replace the filedialog
line with file_name = '\example\file\name'
, no such issue occurs. How can I make the window appear without needing to click on the icon?
from tkinter import Tk, filedialog, Label
root = Tk()
root.withdraw()
file_name = filedialog.askopenfilename(parent=root, title="Select File")
if file_name:
Label(root, text=file_name, padx=20, pady=20).pack()
root.update()
root.deiconify()
root.mainloop()
else:
root.destroy()
Edit: Interestingly, if I add cursor="cross"
to the Label
, the cursor does indeed change to a cross when hovering over the location in the screen where the window eventually appears. So it seems to be there somehow, and is just invisible.
Upgrading to Python 3.12 fixed the issue.