使用tkinter按钮更改不具有功能的变量的值 [英] change value of a variable without a function using a tkinter button
本文介绍了使用tkinter按钮更改不具有功能的变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是编程新手,我想知道是否可以通过Tkinter按钮调用函数来更改变量的值.因为我必须提供一个 command
函数来更改任何变量的值.
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.
赞:
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.
可能看起来像这样:
command = (a = 2)
推荐答案
您必须使用一个函数,否则它将无法正常工作.
You have to use a function, otherwise it won't work.
这篇关于使用tkinter按钮更改不具有功能的变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文