This is a question about changing the button when Python Windows is running

Asked 2 years ago, Updated 2 years ago, 17 views

from tkinter import *
window=Tk()

button1=Button (window, text="Button1")
button2=Button (window, text="Button2")
button3=Button (window, text="Button3")
button4=Button (window, text="Button 4")

button1.pack()
button2.pack()
button3.pack()
button4.pack()

window.mainloop()

I'd like to know if there's a way to make a button like the button I pressed the second time I pressed it when I pressed one button after I ran and pressed another button

python

2022-09-20 15:06

1 Answers

I don't know about Tkinter, but there are usually two approaches.

def btnfunc1() :
    # blah blah blah blah
def btnfunc2() :
    # this and that

# The original function of button 2 is initially specified
btn2.pushed = btnfunc2

# with subsequent conditions
if (btn2.push()) :

    # to designate the function as something else and execute it
    btn2.pushed = btnfunc1
    btnfunc1()

There's no answer, but think about it carefully.


2022-09-20 15:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.