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='root')
- 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)
- def data():
- opt_selected = []
- btn = []
- for i in range(10):
- Label(frame,text=questions[i]).grid(row = i*8+1,column = 1,rowspan=2)
- b_val=0
- btn.append(0)
- opt_selected.append(0)
- opt_selected[i] = IntVar()
- while b_val<4:
- btn[i] = Radiobutton(frame, text=options[i][b_val], variable=opt_selected[i], value=b_val+1)
- btn[i].grid(row = b_val+i*8+3,column = 1)
- b_val+=1
- opt_selected[i].set(0)
- Label(frame,text = "").grid(row = 8*i,column = 1)
- #### Label(frame,text=questions[1]).grid(row = 7,column =2,rowspan=2)
- #### b_val=0
- #### opt_selected = IntVar()
- #### while b_val<4:
- #### btn = Radiobutton(frame, text=options[1][b_val], variable=opt_selected, value=b_val+1)
- #### btn.grid(row = b_val+9,column = 2)
- #### b_val+=1
- #
- def myfunction(event):
- canvas.configure(scrollregion=canvas.bbox("all"),width=1330,height=730)
- def create_options():
- b_val = 0
- b = []
- ht=75
- opt_selected = IntVar()
- while b_val<4:
- btn = Radiobutton(frame, text="", variable=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
- root=Tk()
- root.geometry("1350x750+0+0")
- myframe=Frame(root,width=400,height=600,bd=1)
- myframe.place(x=0,y=0)
- canvas=Canvas(myframe)
- frame=Frame(canvas)
- myscrollbar=Scrollbar(myframe,orient="vertical",command=canvas.yview)
- canvas.configure(yscrollcommand=myscrollbar.set)
- myscrollbar.pack(side="right",fill="y")
- canvas.pack(side="left")
- canvas.create_window((0,0),window=frame,anchor='nw')
- frame.bind("<Configure>",myfunction)
- data()
- root.mainloop()
Add Comment
Please, Sign In to add comment