I am having data in a text file.
AAA
BBB
CCC
111
222
333
!!!
@@@
###
XXX
YYY
ZZZ
No issue to read the file and able to assigned dict. Dict consist of key and pair list. One of the random keys selected and from the associated list a random line will pick up as a question. Associated question with the label.
The remaining element became the answers. Tried to set up a dynamic checkbox but was unable to pause the execution. For now, the idea is to get value via Checkbutton
s and if it's part of the same pair, it should move to the next iteration.
I tried few things but was unable to handle return value. Not my method is correct. Should I use cmd button instead of waiting for Checkbutton
clicks?
Here is my revised code:
import tkinter
from tkinter import *
import random
window = Tk()
def quiz():
chkValue = IntVar()
QL = Label(window,text = (Q), bg = "Blue").pack()
for x in range(len(cpll[key])):
chkValue[x] = Variable()
print(cpll[key][x])
QA[x] = Checkbutton(window,text = cpll[key][x],var=chkValue[x], command=nextq).pack()[x],var=chkValue, command=nextq).pack()
def nextq():
pass
# Using readlines()
file1 = open('cpll.txt', 'r')
lines = file1.readlines()
cpll ={}
count = 0
idx = 0
for line in lines:
if line == "\n":
idx +=1
count += 1
else:
cpll.setdefault(idx,[]).append(line.strip())
count += 1
for key, values in cpll.items():
print(key)
if(isinstance(values, list)):
for value in values:
print(value)
else:
print(value)
for value in cpll.values():
print(value)
key_list = list(cpll)
random.shuffle(key_list)
d2 = {}
for key in key_list:
d2[key] = cpll[key]
Q = random.choice(cpll[key])
cpll[key].remove(Q)
quiz()
window.mainloop()