[Python] Why does the button recognize clicks despite deactivation?

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

  1. Stack

    Stack Membro Participativo

    Program outline: show a helpfile (PDF) on button click -> runs well

    But if I press the button even though the file is still open, the frontend remembers this and then opens the file as often as it was clicked as soon as I close the helpfile. So I decided to deactivate the button.

    Unfortunately it did not help. It remembers every click until the program crashes.

    def openHelpfile():
    helpfile_btn.config(state=DISABLED)
    os.system("helpfile.pdf")
    helpfile_btn.config(state=NORMAL)

    ## FRONTEND =====================
    main_window = Tk()
    main_window.protocol("WM_DELETE_WINDOW", close_window)
    style = Style("darkly")
    main_window.title("SPC Tool: Pyro v4")
    main_frame = Frame(main_window)
    main_frame.pack(padx=10, pady=10)

    status_frame = LabelFrame(main_frame, text="Programm Status")
    status_frame.grid(row=3, column=0, sticky="ew", pady=5)
    statusbar = Text(status_frame, height=1, width=1, font=("", 8, "normal"))
    statusbar.pack(side="left", expand=True, fill="both", padx=10, pady=10)
    helpfile_btn = Button(
    status_frame,
    text="?",
    command=openHelpfile,
    width=5,
    bootstyle="-secondary-outline",
    )
    helpfile_btn.pack(side="right", padx=10, pady=10)

    Continue reading...

Compartilhe esta Página