change value of a variable without a function using a tkinter button

徘徊边缘 提交于 2020-01-24 00:28:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!