[Python] Set button command to None but no effect in python tkinter

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I want to remove button's click event when click it, but this code has no effect. Every button popup msgbox again and again:

    from tkinter import *
    from tkinter import messagebox

    root = Tk()
    root.geometry("500x500+400+200")

    def show_btn(b):
    messagebox.showinfo(message=f"{b.cget('text')}")
    b.config(command=None)

    for x in range(3):
    btn = Button(root, text=f"{x}")
    btn.config(command=lambda b=btn: show_btn(b))
    btn.pack()

    root.mainloop()

    Continue reading...

Compartilhe esta Página