2017-01-17 1 views
0

tkinter를 사용하여 퀴즈를 만들고 작은 문제가 발생했습니다. 첫 번째 질문에 대한 답을 선택하고 제출을 클릭하면 다음 질문에 대한 이전 질문에서 동일한 라디오 버튼이 이미 선택됩니다. 어쩌면 페이지를 새로 고침하여 다음 질문에 대해 선택된 대답이 없도록 할 수 있습니까?새로 고침 라디오 버튼 선택

이미지에 첫 번째 질문에 대한 대답이 표시됩니다. 제출을 클릭 한 후

The image shows an answer being selected for the first question.

은 같은 라디오 버튼 선택은 이미 선택되어 있습니다.

after having clicked submit, the same radio button choice is already selected.

var = IntVar() 

ans1 = Radiobutton(root, text=answer1[count], variable=var, value=1, 
        command=sel) 
ans2 = Radiobutton(root, text=answer2[count], variable=var, value=2, 
        command=sel) 
ans3 = Radiobutton(root, text=answer3[count], variable=var, value=3, 
        command=sel) 
ans4 = Radiobutton(root, text=answer4[count], variable=var, value=4, 
        command=sel) 

ans1.pack() 
ans2.pack() 
ans3.pack() 
ans4.pack() 

def out(): 
    global QuestionNo,correct,incorrect,s,count 
    global ans1, ans3, ans3 ,ans4, correctans 
    # count = count + 1 

    answer = (ans1 or ans2 or ans3 or ans4(var.get())) 

    print (question[QuestionNo]) 


    # print (answer[count]) 
    if count != 3: 
      if answer == correctans : 
       count = count + 1 
       QuestionNo = QuestionNo + 1 
       # entry.delete(0, END) 
       correct = correct + 1 
       label.config(text = question[QuestionNo]) 
      else: 
       QuestionNo = QuestionNo + 1 
       count = count + 1 
       # entry.delete(0, END) 
       incorrect = incorrect + 1 
       label.config(text = question[QuestionNo]) 

      # answer.delete(0, END) 
    elif count == 3: 
     # entry.delete(0, END) 
     label.config(text = "Correct: "+str(correct) + " Incorrect: "+str(incorrect)) 

    ans1.configure(text=str(answer1[count])) 
    ans2.configure(text=str(answer2[count])) 
    ans3.configure(text=str(answer3[count])) 
    ans4.configure(text=str(answer4[count])) 

button = tk.Button(root,text = "Submit",command = out) 
button.pack() 
+0

은'var.set (0)'을 사용합니다. BTW : 당신은 오히려'대답 = var.get()'이 필요합니다. 'Answer1 [count]'가 텍스트이면,'str()'을 쓸 필요가 없다. – furas

+0

BTW : 코드를 더 읽기 쉽도록 만들기'root = Tk()'전에 모든 함수를 넣는다. – furas

+0

고마워, furas –

답변

0

사용 var.set(0)는 선택을 재설정합니다.

0

다른 질문 페이지의 라디오 버튼에 var를 사용 했습니까? 당신은 페이지 1에 대해 var1을 사용하고 페이지 2에 대해 var2를 사용하여 이월을 피할 수 있습니다.