0

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))
1

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.