1

I am new to programming and I want to know If there is any way to change the value of a variable with a Tkinter button out calling a function. As I have to give a function as command to change the value of any variable.

Like this:

import tkinter as tk

a = 1


def test():
    global a
    a = 2
    return


root = tk.Tk()

b = tk.Button(root, text="Click", command=test)
b.pack()

root.mainloop()

But I want to know if there is a way to do it directly without using any function.

Something that might look like this:

command = (a = 2)
4
  • 3
    nope, you have to use a function, but why don't you want to use it? Commented Jan 4, 2020 at 17:52
  • 1
    @TijmenThankyou Sir, For your quick response, I just wanted to know if it was possible as there is a chance of running into errors if one has to change the value of more than one variable. Commented Jan 4, 2020 at 17:59
  • What kind of errors, Maybe I can help? Commented Jan 4, 2020 at 18:03
  • @Tijmen No thanks, I just meant "There is a Chance" of running into errors. Commented Jan 4, 2020 at 18:05

1 Answer 1

1

You have to use a function, otherwise it won't work.

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.