Question

In: Computer Science

Hi, I'm trying to make a basic GUI quiz in python using tkinter. I would like...

Hi,

I'm trying to make a basic GUI quiz in python using tkinter.

I would like the user to have to press a start button to begin the quiz and then be asked 5 different questions with the total score showing at the end. Ideally it would be a multiple choice quiz with the user having 4 different answers to choose from.

A very basic example of this would be appreciated so I can understand where exactly I'm going wrong.

Thanks in advance

Solutions

Expert Solution

#source code:

from tkinter import *
import random
q=["days in a year",
"kind of apple",
"How many days in a week",
"What is the Capital of AndhraPradesh",
"who is the Present C.M of AndhraPrasad"
]
options=[
   ["365","368","410","362"],
   ["heat","non-veg","vegatable","fruit"],
   [3,8,7,9],
   ["Hyderabad","Rajahmundry","Amaravathi","Guntur"],
   ["Pawan Kalyan","ChandraBabu Naidu","K.A Paul","Jagan"]
]
a=[1,4,3,3,4]
rand_show=random.sample(range(5),5)
class Quiz:
   def __init__(self,master):
       self.opt_selected=IntVar()
       self.qn=0
       self.r=rand_show[self.qn]
       self.correct=0
       self.ques=self.create_q(master,self.qn,self.r)
       self.opts=self.create_options(master,4)
       self.display_q(self.qn,self.r)
       self.button=Button(master,text="Submit",command=self.next_btn)
       self.button.pack(side=BOTTOM)
      
   def create_q(self,master,qn,r):
       w=Label(master,text=q[r])
       w.pack(side=TOP)
       return w
   def create_options(self,master,n):
       b_val=0
       b=[]
       while b_val<n:
           btn=Radiobutton(master,variable=self.opt_selected,value=b_val+1)
           b.append(btn)
           btn.pack(side=TOP,anchor="w")
           b_val=b_val+1
       return b
   def display_q(self,qn,r):
       b_val=0
       temp=qn
       self.opt_selected.set(0)
       self.ques['text']=str(temp+1)+"."+q[r]
       for op in options[r]:
           self.opts[b_val]['text']=op
           b_val=b_val+1
          
   def check_q(self,r):
       if self.opt_selected.get()==a[self.r]:
           return True
       return False
   def print_results(self):
       root.destroy()
       king=Tk()
       king.geometry("500x300")
       Label(king, text="YOUR WEEKEND RESULTS:").pack()
       Label(king, text="").pack()
       score="Marks: "+str(self.correct)+"/"+str(len(q))
       Label(king, text=score,fg="green").pack()
       marks=0
       id=""
       print(marks)
   def next_btn(self):
       if self.check_q(self.r):
           print("correct")
           self.correct+=1
       self.qn=self.qn+1
       if(self.qn==5):
           pass
       else:
           self.r=rand_show[self.qn]

       if self.qn>=len(q):
           self.print_results()
          
       else:
           self.display_q(self.qn,self.r)
          
root=Tk()
root.geometry("500x300")

app=Quiz(root)
root.mainloop()
      
          

#output:

#if you have any doubts comment below....


Related Solutions

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...
Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as...
I did the complete programming in python , just want to use tkinter for GUI. please...
I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you. import random image = 'w' # modified functions which accepts two numbers each and returns the respective # output def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def kidCalc():...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter...
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter and no other GUI product. Design a small (ie 2x3) GUI window which contains 4 items: 1. A text keyin field, 2. An Execute button, 3. An Exit Button 4. A label. When the user clicks on the execute button, the text located in the keyin field will be displayed on the label. If the keyin field contains no text, a message box should...
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar,...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar, and a Menu bar FOR THE QUESTION BELOW: PLEASE HELP PROGRAMMING LANGUAGE IS PYTHON Write a simple quiz game that has a list of ten questions and a list of answers to those questions. The game should give the player four randomly selected questions to answer. It should ask the questions one-by-one, and tell the player whether they got the question right or wrong....
i have a project where i would like to make organic chicken to look green. I'm...
i have a project where i would like to make organic chicken to look green. I'm looking for a technology that can do that. Also I'm searching for high level milestones for the project. Any ideas to help me out for the project?
Hi, I would like the following python code rewritten in a different way/structure etc. I got...
Hi, I would like the following python code rewritten in a different way/structure etc. I got it from a question I posted but am worried fellow classmates will also be using it so am covering bases. her it is. #threeUniqueSongs.py #Simulation of professor listening to 3 songs out of playlist of 4 songs 10000 times sampling with replacement possible import random import math #Here playlist is the list of 4 songs i.e. "Eastside", "Better Now", "Lucid Dreams", "Harder, Better, Faster,...
Hi! Below is the case study and I want to make sure I'm on the right...
Hi! Below is the case study and I want to make sure I'm on the right track. I bolded the questions I'm interested in (1-5). Looking for people who are familiar with the DSM-5/abnormal psychology and able to answer all questions completely. Thank you! Detailed answers extremely appreciated! Questions: 1. Diagnosis; what is the evidence for it? 2. Treatment; typical treatment used for this diagnosis AND most effective treatment. IF the person is in treatment, what should we target first...
Hi! Below is the case study and I want to make sure I'm on the right...
Hi! Below is the case study and I want to make sure I'm on the right track. I bolded the questions I'm interested in (1-5). Looking for people who are familiar with the DSM-5/abnormal psychology and able to answer all questions completely. Thank you! - no ICD 10 please! Questions: 1. Diagnosis; what is the evidence for it? For this one, assume the patient has borderline disorder and answer the rest accordingly. 2. Treatment; typical treatment used for this diagnosis...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT