Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makes user change Tkinter button if clicked?

Tags:

python

tkinter

I have this code:

def userChoice():
    text = "Clicked"


row1 = Button(root, text=" ", command = "userChoice")
row1.config(height="6", width="10")
row1.grid(row=0, column=0)

I want to make it so that when the user clicks the button the text is changed. I am not sure how I would do this I ran this code and when the button is clicked nothing happens? I know this is a very simple question but just cannot figure out how to do it. I have been trying for the pas hour or so.

like image 555
user3678184 Avatar asked Jun 13 '26 17:06

user3678184


1 Answers

You can use row1["text"] to set new value:

from Tkinter import *

root = Tk()

def userChoice():
    row1["text"] = "CLICKED!"


row1 = Button(root, text=" ", command = userChoice)
row1.config(height="6", width="10")
row1.grid(row=0, column=0)

mainloop()
like image 184
NorthCat Avatar answered Jun 15 '26 07:06

NorthCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!