如何根据另一个模块的变量自动更新 Label
。有任何“类似角”的图案吗?
以下内容无效,更多是伪代码。
main.py
import myStatusStoreModule
# The label should update when points changes
Label(self, textvariable=myStatusStoreModule.points)
myStatusStoreModule.py
points = 0
def addPoints(p):
global points
points += p
# here could be a event listener that modifies points as well
有什么主意吗?
谢谢!
答案 0 :(得分:1)
textvariable
将自动更新如果您提供的变量是tkinter变量。
import Tkinter as tk
points = tk.IntVar()
def addPoints(p):
global points
points.set(points.get() + p)
您最好在一个面向初学者的论坛(例如:Learnpython.reddit.com)中提出这样的问题