Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import MySQLdb
- from tkinter import *
- conn = MySQLdb.connect(host='localhost', database='world', user='root', password='veer1811')
- cursor = conn.cursor()
- global questions
- questions = []
- global options
- options = []
- global answers
- answers = []
- answerstemp =[]
- s1=set()
- while len(s1)<10:
- strQ=""
- strA=""
- id = random.randint(1, 30)
- s1.add(id)
- print(s1)
- while len(s1)>0:
- s = "select qstn from questions where QID=%d"
- id = s1.pop()
- arg = (id)
- cursor.execute(s % arg)
- strQ = strQ.join(list(cursor.fetchone()))
- questions.append(strQ)
- s = "select opA,opB,opC,opD from questions where QID=%d"
- arg = (id)
- cursor.execute(s % arg)
- options.append(list(cursor.fetchone()))
- s = "select ans from questions where QID=%d"
- arg = (id)
- cursor.execute(s % arg)
- l = list(cursor.fetchone())
- answerstemp.append(l)
- print(questions)
- print(options)
- mydict={}
- for i in range(10):
- mydict[questions[i]]=options[i]
- for key,val in mydict.items():
- print(key,"---->",val)
- print("\n")
- for i in range(len(answerstemp)):
- answers.append(answerstemp[i][0])
- print(answers)
- cursor.close()
- conn.close()
- l1={}
- for i in range(10):
- l1[i]=0
- print(l1)
- class Quiz:
- def __init__(self, master):
- global mReg
- mReg = master
- self.master = master
- self.master.geometry("1350x750+0+0")
- self.master.title("Online Quiz - Registration")
- self.master.config(bg="azure")
- global f1
- f = Frame(self.master, height=1080, width=1920, bg="azure", relief="ridge", bd=20)
- f.propagate(0)
- f.pack()
- self.qno = 0
- self.score1 = 0 # self.correct
- self.ques = self.create_q(f, self.qno)
- self.opts = self.create_options(f)
- self.display_q(self.qno)
- self.Back = Button(f, text="<-Back",command = self.back).place(x=265,y=225)
- self.Next = Button(f, text="Next->",command=self.next ).place(x=315,y=225)
- self.submit=Button(f, text="Submit",fg="white",bg="blue").place(x=290,y=275)
- self.score=Label(f,text="",bg='azure').place(x=200,y=300)
- def create_q(self, master, qno):
- qLabel = Label(master, text=questions[qno])
- qLabel.place(x=40,y=70)
- return qLabel
- def create_options(self,master):
- b_val = 0
- b = []
- ht=75
- self.opt_selected = IntVar()
- while b_val<4:
- btn = Radiobutton(master, text="", variable=self.opt_selected, value=b_val+1)
- b.append(btn)
- ht=ht+25
- btn.place(x=30,y=ht)
- b_val = b_val + 1
- return b
- def display_q(self, qno):
- b_val = 0
- print(qno)
- self.ques['text'] = str(qno+1)+". "+questions[qno]
- for op in options[qno]:
- self.opts[b_val]['text'] = op
- b_val = b_val + 1
- print(l1)
- #is chutiye ne bahot dimaag khaya
- #Atleast ab ans save ho rha hai after press of next button karta hu baki ka
- def next(self):
- self.qno += 1
- l1[self.qno-1]=self.opt_selected.get()
- self.opt_selected.set(l1[(self.qno)])
- if self.qno >= len(questions):
- pass
- #self.display_results()
- else:
- self.display_q(self.qno)
- def back(self):
- l1[self.qno]=self.opt_selected.get()
- self.qno -= 1
- c=l1[self.qno]
- print(c)
- self.opt_selected.set(c)
- if self.qno < 0:
- pass
- #self.display_results()
- else:
- self.display_q(self.qno)
- root = Tk()
- root.resizable(0,0)
- RegObj = Quiz(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment