python - 为什么 python tkinter 标签不显示计算结果
问题描述
我是 python 新手。我想在我的游戏中做一个计分器。但是tkinter
标签不能显示正确的结果。如果我是,它可以显示 1 分。但如果我在其他问题上是对的。它不能显示2分。我想问任何可以显示int
和计算结果的 方法.config
这里是我的代码的一些部分。
#function to count score
def count():
global num
num = 0
if fruits_word == ans.get():
num += 1
score_label.config(text="%d" % num)
else:
num -= 1
score_label.config(text="%d" % num)
#create a label to show the score
score_label = tk.Label(root, text="", font=("helvetica",16))
score_label.pack(pady=15)
#create a button to check the ans and count the score
ans_button = tk.Button(root, text="Answer", command=lambda: [answer(), count()])
ans_button.pack(pady=15)
解决方案
推荐阅读
- jenkins - 下面提到的语法在运行 Jenkins 管道时会做什么?agent [ label 'slave' ]
- python - 如何将值从一个数组推送到另一个数组,一个接一个的索引
- javascript - 动态更改 Javascript 项目中的 og 元标记以进行社交媒体共享
- swift - SwiftUI:更改 macOS 上的默认命令菜单
- reactjs - 令牌在 Reactjs 应用程序中无效
- javascript - D3.js 双摆奇怪行为
- c++ - 并行化for循环并合并线程私有变量
- java - Selenium:无法在 Linux 上找到浏览器二进制文件
- favicon - 如何查看 .ico 图标/图标的所有图层/分辨率?
- c# - 无法将 tiff 图像转换为位图(矩阵)