python - 像 Angular 一样自动更新 tk.Label?
问题描述
如何根据另一个模块的变量自动更新一个。Label
有没有“类似Angular”的模式?
以下内容不起作用,更多的是作为伪代码。
主文件
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
任何想法?
提前致谢!
解决方案
textvariable
如果您给它的变量是 tkinter 变量,它将自动更新。
import Tkinter as tk
points = tk.IntVar()
def addPoints(p):
global points
points.set(points.get() + p)
您最好在 learnpython.reddit.com 等面向初学者的论坛中提出此类问题
推荐阅读
- python - 带有 2D 切片的 numpy 视图
- java - 为自己的类定义一个单独的接口,然后该类实现它的主要优点是什么?
- react-native - 如何“正确”更新我在 PlayStore 上的应用
- python - 这是什么意思?关键错误:'GC'
- flutter - 400 错误:BadRequest - 从 Flutter 桌面发送到 Firebase 本地存储模拟器的 HTTP 请求
- r - 为什么我的直方图在 x 轴上没有负值?
- android - 在 React Native 中,如何“动态”更改 Android 应用程序图标?
- c# - 捕获 TableLayoutPanel 特定区域的图像
- django - 将数据字典与模型实例解析为 Django ModelForm
- python - 使用 pandas 获取两个数据框之间的匹配值