[Python] Why is my code closing right after I run it by doubleclicking? [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    This code reproduces my problem (it's just a button that does nothing):

    import customtkinter as tk

    tk.set_appearance_mode("dark")
    tk.set_default_color_theme("dark-blue")

    root = tk.CTk()

    root.title("File Organizer")
    root.iconbitmap("assets/icon.ico")
    root.geometry("600x350")

    run_button = tk.CTkButton(root, text="Run", height=45, width=90,
    font=("Helvetica", 23), corner_radius=18)
    run_button.pack(padx=5)

    if __name__ == '__main__':
    root.mainloop()


    When I run it or any other piece of code that I have written (except for code using tkinter) by doubleclicking the corresponding Python script, the program immediately closes, but if I use an IDE or run it through the terminal, there's no issue, how can I fix it?

    Continue reading...

Compartilhe esta Página