问题
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)
回答1:
You have to use a function, otherwise it won't work.
来源:https://stackoverflow.com/questions/59593277/change-value-of-a-variable-without-a-function-using-a-tkinter-button