Apr-12-2017, 07:26 AM
ok so i need to create a program in tkinter with upto 50 question and 4 options respective to each question now for testing i have added loops but now i need to add the actual quiz questions and options for the same and i am stuck here as to how exactly do i get it working properly i need to shuffle the options provided (questions as well if its possible)
Ps- i am new to tkinter many things might seems complex to me but i am trying to understand
Ps- i am new to tkinter many things might seems complex to me but i am trying to understand
try: import tkinter as tk from tkinter import messagebox except ImportError: import Tkinter as tk import tkMessageBox as messagebox class VerticalScrolledFrame: def __init__(self, master, **kwargs): self.outer = tk.Frame(master) self.vsb = tk.Scrollbar(self.outer, orient=tk.VERTICAL) self.vsb.pack(fill=tk.Y, side=tk.RIGHT) self.canvas = tk.Canvas(self.outer, highlightthickness=0, **kwargs) self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) self.canvas['yscrollcommand'] = self.vsb.set self.canvas.bind("<Enter>", self._bind_mouse) self.canvas.bind("<Leave>", self._unbind_mouse) self.vsb['command'] = self.canvas.yview self.inner = tk.Frame(self.canvas) self.canvas.create_window(4, 4, window=self.inner, anchor='nw') self.inner.bind("<Configure>", self._on_frame_configure) self.outer_attr = set(dir(tk.Widget)) def __getattr__(self, item): if item in self.outer_attr: return getattr(self.outer, item) else: return getattr(self.inner, item) def _on_frame_configure(self, event=None): self.canvas.configure(scrollregion=self.canvas.bbox("all")) def _bind_mouse(self, event=None): self.canvas.bind_all("<4>", self._on_mousewheel) self.canvas.bind_all("<5>", self._on_mousewheel) self.canvas.bind_all("<MouseWheel>", self._on_mousewheel) def _unbind_mouse(self, event=None): self.canvas.unbind_all("<4>") self.canvas.unbind_all("<5>") self.canvas.unbind_all("<MouseWheel>") def _on_mousewheel(self, event): """Linux uses event.num; Windows / Mac uses event.delta""" if event.num == 4 or event.delta == 120: self.canvas.yview_scroll(-1, "units" ) elif event.num == 5 or event.delta == -120: self.canvas.yview_scroll(1, "units" ) root=tk.Tk() root.geometry('700x700+400+400') root.title('Quiz Program') welcom=tk.Label(root,text="Welcome To Quiz") welcom.pack() def mquit(): mexit=messagebox.askyesno(title="Quit",message="Quit The Test ?") if mexit > 0: root.destroy() return answers = {} labels = {} question_frame = VerticalScrolledFrame(root, height=500) question_frame.pack(fill=tk.X) for i in range(1, 26): answers[i] = tk.IntVar() labels[i] = tk.Label(question_frame, text="This Is Question %d :" % i) labels[i].pack() for j in range(1, 5): btn = tk.Radiobutton(question_frame, text="Option %d" % j, value=j, variable=answers[i]) btn.pack() #i need to add four options and point out 1 right answer out of 4 option provided #labels will also change as i'll add each question into the program (upto 50questions) mbutton=tk.Button(root,text='Quit',command=mquit,fg='red',bg='blue') mbutton.pack() root.mainloop()