OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Withdrawn window not reappearing with deiconify after filedialog in Tkinter on MacOS

  • Thread starter Thread starter TimH
  • Start date Start date
T

TimH

Guest
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?

Code:
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()
<p>The code below is meant to ask for a file name with <code>filedialog</code> 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 <code>deiconify</code> 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 <code>filedialog</code> line with <code>file_name = '\example\file\name'</code>, no such issue occurs. How can I make the window appear without needing to click on the icon?</p>
<pre class="lang-py prettyprint-override"><code>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()
</code></pre>
 

Latest posts

A
Replies
0
Views
1
Alvah_Franey
A
H
Replies
0
Views
1
habrewning
H
Top