python - Tkinter Drop down Menu -
i trying add entry fields based on tkinter dropdown menu not sure doing correctly. when select option on 1 of drop down menu not getting new entry fields popping up. code have far. have tried putting if statements in external function , putting command inside optionmenu , still did not work.
tkinter import * def callback(): numques = int(e1.get()) = 0 while <= numques: variable = stringvar(top) variable.set("questions type") # default value w = optionmenu(top, variable, "short answer", "multiple choice", "fill in blank", "true of false", "matching", "ordering") w.grid(row = i*2+2, column=0) ques = stringvar(top, value='question') ans = stringvar(top, value='answer') choice = stringvar(top, value='answer choices') if variable.get() == "short answer": q = entry(top, bd = 5, textvariable = ques) q.grid(row=i*2+2, column = 2, columnspan=2) = entry(top, bd = 5, textvariable = answ) a.grid(row=i*2+2, column = 4, columnspan=2) if variable.get() == "multiple choice": q = entry(top, bd = 5, textvariable = ques) q.grid(row=i*2+2, column = 2, columnspan=2) c = entry(top, bd = 5, textvariable = answ) c.grid(row=i*2+2, column = 4, columnspan=2) = entry(top, bd = 5, textvariable = answ) a.grid(row=i*2+2, column = 6, columnspan=2) if variable.get() == "true or false": q = entry(top, bd = 5, textvariable = ques) q.grid(row=i*2+2, column = 2, columnspan=2) = entry(top, bd = 5, textvariable = answ) a.grid(row=i*2+2, column = 6, columnspan=2) if variable.get() == "fill in blank": q = entry(top, bd = 5, textvariable = ques) q.grid(row=i*2+2, column = 2, columnspan=2) = entry(top, bd = 5, textvariable = answ) a.grid(row=i*2+2, column = 4, columnspan=2) if variable.get() == "ordering": q = entry(top, bd = 5, textvariable = ques) q.grid(row=i*2+2, column = 2, columnspan=2) = entry(top, bd = 5, textvariable = answ) a.grid(row=i*2+2, column = 4, columnspan=2) = i+1 top = tk() top.geometry("600x600") top.title("ecampus quiz developer") l1 = label(top, text="how many questions quiz be?") l1.grid(row=0, column=0) e1 = entry(top, bd = 5) e1.grid(row=0, column=1) mybutton1 = button(top, text="submit", width=10, command=callback) mybutton1.grid(row=1, column=1) top.mainloop()
wiki
Comments
Post a Comment