Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to remove the background window that pops up when calling askopenfilename()?

When I call the basic command:

from tkinter.filedialog import askopenfilename

filename = askopenfilename()

A little window pops up behind the selector screen.

enter image description here

Is there a way to remove this?

like image 925
Tom Cupis Avatar asked Jan 06 '23 15:01

Tom Cupis


1 Answers

It pops up because you need at least a "root" window for each tkinter application. In your case, you aren't creating any root window explicitly, so askopenfilename creates it automatically for you. One solution would be to create the root window explicitly and then hide it, something as follows

from tkinter.filedialog import askopenfilename
from tkinter import Tk

Tk().withdraw()
filename = askopenfilename()
like image 67
nbro Avatar answered Jan 09 '23 03:01

nbro