How to prevent Tkinter window opening before being called? How to prevent Tkinter window opening before being called? tkinter tkinter

How to prevent Tkinter window opening before being called?


The window master does open only after the file dialog closure (try to change its title to check), the first window you see is the parent window of the file dialog. Indeed, the tkinter file dialogs are toplevel windows, so they cannot exist without a parent window. So the first window you see is the parent window of the file dialog.

The parent window can however be hidden using the withdraw method and then restored with deiconify:

from tkinter import Tkfrom tkinter.filedialog import askopenfilenamedef main():    master = Tk()    master.withdraw()  # hide window    my_file = askopenfilename(parent=master)    master.deiconify()  # show window    master.mainloop()if __name__ == '__main__':    main()