나는 Tkinter에 객관식 퀴즈를 만들고 Radiobuttons와 checkbuttons를 사용하고 있습니다. 이 질문에 대해서는 라디오 버튼을 사용하고 있습니다. 'Calculate Score'if 문에서 라디오 버튼의 값을 비교하려면 어떻게해야합니까? 컴퓨터는 'calculate_score_1()이 정확히 1 개의 인수 (주어진 0)'을 가져옵니다. 'tkinter의 라디오 버튼에서 값을 얻으려면 어떻게해야합니까?
또한 클래스간에 변수를 전달하려면 어떻게해야합니까? 나는 10 개의 질문에 대해 10 개의 클래스를 가지고 있지만, 사용자가 대답을 올바르게 할 때 점수에 1을 더하면 변수 '점수'에 액세스 할 수 있기를 원합니다.
class Question_1_Window(tk.Toplevel):
'''A simple instruction window'''
def __init__(self, parent):
tk.Toplevel.__init__(self, parent)
self.text = tk.Label(self, width=75, height=4, text = "1) Do you have the time to do at least twenty minutes of prefect duty each week?")
self.text.pack(side="top", fill="both", expand=True)
question_1_Var = IntVar() #creating a variable to be assigned to the radiobutton
Yes_1 = Radiobutton(self, text = "Yes", variable = question_1_Var, value=1, height=5, width = 20)
Yes_1.pack() #creating 'yes' option
#Here we are assigning values to each option which will be used in the validation
No_1 = Radiobutton(self, text = "No", variable = question_1_Var, value=2, height=5, width = 20)
No_1.pack() #creating 'no' option
def calculate_score_1(self):
Enter_1.config(state="disabled")
#self.question_1.config(state="disabled")
if (question_1_Var.get() == 1) and not (question_1_Var.get() == 2):
print("calculate score has worked") #test lines
#score = score + 1
else:
print("not worked") #testlines
Enter_1 = Button(self, text= "Enter", width=10, command = calculate_score_1)
Enter_1.pack()
또한 (get()을 사용하는 것과 같이) 도움을 준 질문에 대한 대답을 수락하고/또는 upvote 할 수 있다면 좋을 것입니다. 이것은 사람들로 하여금 앞으로 귀하의 질문에 계속 대답하도록 동기를 부여합니다. –
죄송합니다,이 사이트를 처음 사용하고 답변을 업데이트 할 수 없음을 알고 있습니다 – user3056786
아무런 문제가 없습니다. 언젠가는 새 소식이 있습니다. 도움이 될만한 대답 (또는 다른 질문)을 발견하면, 그것을 upvote해야합니다. 또한 질문에 가장 적합한 대답이있는 경우 답변을 '수락'할 수 있습니다. 작은 화살표를 사용하고 질문 옆의 숫자로 체크 표시를하십시오. –