我真的是 GUI 和 python 本身的新手。我正在尝试使用 tkinter 在 python 3.x 中制作一个简单的琐事游戏。这个想法是它会有多个问题,会告诉你你做对了还是错了,以及告诉你做对了多少。然而,我遇到的问题是,由于某种原因,我所有的按钮都表现得好像它们在没有被点击时被点击过一样。代码如下:
from tkinter import *
class Correct(object):
value = True
def __init__(self, text):
self.text = text
class Incorrect(object):
value = False
def __init__(self, text):
self.text = text
def check(value):
if value == True:
print("you picked the right answer!")
else:
print("sorry thats not right")
question1 = ["this is a question", Correct("right answer"), Incorrect("wrong b"), Incorrect("wrong c"),
Incorrect("wrong d")]
master = Tk()
qlabel1 = Label(master,text=question1[0])
# buttons
choice1 = Button(master, text=question1[1].text, command=check(question1[1].value))
choice2 …Run Code Online (Sandbox Code Playgroud)