首页 > 解决方案 > 为什么 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)

标签: pythontkinter

解决方案


推荐阅读