Guest User

Untitled

a guest
Mar 21st, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import random
  2. import MySQLdb
  3. from tkinter import *
  4.  
  5.  
  6. conn = MySQLdb.connect(host='localhost', database='world', user='root', password='root')
  7. cursor = conn.cursor()
  8.  
  9. global questions
  10. questions = []
  11. global options
  12. options = []
  13. global answers
  14. answers = []
  15. answerstemp =[]
  16. s1=set()
  17.  
  18. while len(s1)<10:
  19. strQ=""
  20. strA=""
  21. id = random.randint(1, 30)
  22. s1.add(id)
  23. print(s1)
  24. while len(s1)>0:
  25. s = "select qstn from questions where QID=%d"
  26. id = s1.pop()
  27. arg = (id)
  28. cursor.execute(s % arg)
  29. strQ = strQ.join(list(cursor.fetchone()))
  30. questions.append(strQ)
  31.  
  32. s = "select opA,opB,opC,opD from questions where QID=%d"
  33. arg = (id)
  34. cursor.execute(s % arg)
  35. options.append(list(cursor.fetchone()))
  36.  
  37. s = "select ans from questions where QID=%d"
  38. arg = (id)
  39. cursor.execute(s % arg)
  40. l = list(cursor.fetchone())
  41. answerstemp.append(l)
  42.  
  43. print(questions)
  44. print(options)
  45. mydict={}
  46. for i in range(10):
  47. mydict[questions[i]]=options[i]
  48. for key,val in mydict.items():
  49. print(key,"---->",val)
  50. print("\n")
  51. for i in range(len(answerstemp)):
  52. answers.append(answerstemp[i][0])
  53.  
  54. print(answers)
  55.  
  56. cursor.close()
  57. conn.close()
  58. l1={}
  59. for i in range(10):
  60. l1[i]=0
  61. print(l1)
  62.  
  63. def data():
  64. opt_selected = []
  65. btn = []
  66. for i in range(10):
  67. Label(frame,text=questions[i]).grid(row = i*8+1,column = 1,rowspan=2)
  68. b_val=0
  69. btn.append(0)
  70. opt_selected.append(0)
  71. opt_selected[i] = IntVar()
  72. while b_val<4:
  73. btn[i] = Radiobutton(frame, text=options[i][b_val], variable=opt_selected[i], value=b_val+1)
  74. btn[i].grid(row = b_val+i*8+3,column = 1)
  75. b_val+=1
  76. opt_selected[i].set(0)
  77. Label(frame,text = "").grid(row = 8*i,column = 1)
  78.  
  79. #### Label(frame,text=questions[1]).grid(row = 7,column =2,rowspan=2)
  80. #### b_val=0
  81. #### opt_selected = IntVar()
  82. #### while b_val<4:
  83. #### btn = Radiobutton(frame, text=options[1][b_val], variable=opt_selected, value=b_val+1)
  84. #### btn.grid(row = b_val+9,column = 2)
  85. #### b_val+=1
  86. #
  87. def myfunction(event):
  88. canvas.configure(scrollregion=canvas.bbox("all"),width=1330,height=730)
  89. def create_options():
  90. b_val = 0
  91. b = []
  92. ht=75
  93. opt_selected = IntVar()
  94. while b_val<4:
  95. btn = Radiobutton(frame, text="", variable=opt_selected, value=b_val+1)
  96. b.append(btn)
  97. ht=ht+25
  98. btn.place(x=30,y=ht)
  99. b_val = b_val + 1
  100. return b
  101. root=Tk()
  102. root.geometry("1350x750+0+0")
  103.  
  104. myframe=Frame(root,width=400,height=600,bd=1)
  105. myframe.place(x=0,y=0)
  106.  
  107. canvas=Canvas(myframe)
  108. frame=Frame(canvas)
  109. myscrollbar=Scrollbar(myframe,orient="vertical",command=canvas.yview)
  110. canvas.configure(yscrollcommand=myscrollbar.set)
  111.  
  112. myscrollbar.pack(side="right",fill="y")
  113. canvas.pack(side="left")
  114. canvas.create_window((0,0),window=frame,anchor='nw')
  115. frame.bind("<Configure>",myfunction)
  116. data()
  117. root.mainloop()
Add Comment
Please, Sign In to add comment