[Python] I cannot launch a TopLevel window after FileDialog execution

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    Why can I not show a TopLevel window after launching the FileDialog module?

    I would like to show a window with a waiting message after executing FileDialog code.


    • If I create the TopLevel window before calling FileDialog, the window is displayed and then the FileDialog code is executed.


    • But if I run FileDialog first, then create the TopLevel, this window is not displayed.

    This code works fine:

    import time
    from tkinter import filedialog
    from tkinter import *

    root = Tk()
    root.title("Main window")
    root.geometry("400x200")
    topLevelWindow = Toplevel(root)
    topLevelWindow.title("Secondary window")
    topLevelWindow.geometry("400x200")
    Label(topLevelWindow, text="Plaese wait...").pack()

    # Choose a file and save the path
    filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = [("All files", "*.*")])
    print("File path: ", filename)


    But if I execute TopLevel code after FileDialog, it does not show the TopLevel window:

    import time
    from tkinter import filedialog
    from tkinter import *

    root = Tk()
    root.title("Main window")
    root.geometry("400x200")

    # Choose a file and save the path
    filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = [("All files", "*.*")])

    topLevelWindow = Toplevel(root)
    topLevelWindow.title("Secondary window")
    topLevelWindow.geometry("400x200")
    Label(topLevelWindow, text="Plaese wait...").pack()

    print("File path: ", filename)


    Thanks in advance for any help!

    I wish to launch TopLevel windows after the FileDialog execution.

    Continue reading...

Compartilhe esta Página