Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有变量引用的Python Tkinter按钮函数调用_Python_Tkinter - Fatal编程技术网

带有变量引用的Python Tkinter按钮函数调用

带有变量引用的Python Tkinter按钮函数调用,python,tkinter,Python,Tkinter,有办法做到这一点吗 WoodInt = GatherWood(WoodInt) 在tkinter按钮上 BWood = tk.Button(Top, text ="Gather Wood", command = GatherWood) 我想做的是每次按下按钮,WoodInt都会上升20。不清楚GatherWood的作用是什么,但是,一种方法是将按钮链接到一个命令,该命令将WoodInt增加20: def increment_woodint_by_20(): global Wood

有办法做到这一点吗

 WoodInt = GatherWood(WoodInt)
在tkinter按钮上

 BWood = tk.Button(Top, text ="Gather Wood", command = GatherWood)

我想做的是每次按下按钮,
WoodInt
都会上升20。

不清楚GatherWood的作用是什么,但是,一种方法是将按钮链接到一个命令,该命令将
WoodInt
增加20:

def increment_woodint_by_20():
    global WoodInt
    Woodint += 20

WoodInt = GatherWood(WoodInt)
BWood = tk.Button(Top, text ="Gather Wood", command=increment_woodint_by_20)
...

我经常听到别人说,使用全局和非局部是一个坏习惯。。。我还有许多其他的聚集按钮,我希望能重新使用聚集功能。然而,实际上,这里使用
global
可以向您展示解决问题的简单方法。要获得更详细的解决方案,请将变量放置在一个类中,以便传递和修改!好的,我还没学会上课,所以我现在可能会去参加环球,谢谢你的建议