The Unknown
The Unknown

Reputation: 1

How do I change value of a variable using a tkinter button?

I have a variable for example: x = 1. And I want to change it to x = 2 using a tkinter button.

I tried:

b1 = Button(root,bg = "black",fg = "white",text = "idk",command = (x=2))

Upvotes: 0

Views: 51

Answers (1)

thturk
thturk

Reputation: 86

U can call a function on command to set your global variable

x=3
b1 = Button(root,bg = "black",fg = "white",text = "idk",command = vall)

def vall():
    global x
    x=2

Upvotes: 2

Related Questions