Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #----------------------------#
- # Created By Joel Malone #
- #----------------------------#
- #Importing Python Packages
- import sys
- import time
- import threading
- from tkinter import *
- from tkinter import ttk
- import tkinter as tk
- #removed globals from here
- LARGE_FONT= ("Verdana", 12)
- countans = 0
- rightans = 0
- score = 0
- timeout = 0
- tog_timecount = 0
- #Dictionary
- qz = {"How many stages are there in the Structured Approach?":"Five",
- "What is a device that provides input into a control system called?":"Sensor",
- "Which of the Following is an example of an emerging technology?":"Manual Correct",
- "What kind of Hardware device is a Keyboard?":"Input",
- "What kind of Hardware device is a Speaker?":"Output",
- "What is the truest definition of copyright?":"Laws in place to safeguard legal intellectual property.",
- "Software developers who develop custom applications :":"Manual Correct",
- "Gradually introducing a new system onto a site is a feature of which method of conversion?":"Phased",
- "Software that simultaneously simulates a specified number of users entering data into an application is an example of what?":"Case Tools",
- "What does the acronym RAM stand for?":"Random Access Memory"}
- class QuizApp(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- tk.Tk.iconbitmap(self, default='icon.ico')
- tk.Tk.wm_title(self, "Bugz - HSC SDD Quiz")
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand = True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {}
- for F in (StartPage, PageFinish, Page1, Page2, Page3, Page4, Page5, Page6, Page7, Page8, Page9, Page10):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame(StartPage)
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise()
- class StartPage(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self,parent)
- label1 = ttk.Label(self, text="Welcome To The Quiz!", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text= "Are you ready to embark on an educational voyage through the realm of Software Design and Development?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- button1 = ttk.Button(self, text="Next", command=lambda: controller.show_frame(Page1))
- button1.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 0)
- progressbar.pack()
- class Page1(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text= "Question 1", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text= "How many stages are there in the Structured Approach?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- combobox = ttk.Combobox(self)
- combobox.config( values = ('One', 'Ten', 'Five', 'Thirteen', 'Six', 'None'))
- combobox.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(StartPage))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page2),submit(combobox.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 1)
- progressbar.pack()
- class Page2(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 2", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="What is a device that provides input into a control system called?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- entry = ttk.Entry(self, text="Question 2", font=LARGE_FONT)
- entry.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page1))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page3),submit(entry.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 2)
- progressbar.pack()
- class Page3(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- rchoice = StringVar()
- label1 = ttk.Label(self, text="Question 3", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="Which of the Following is an example of an emerging technology?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- ttk.Radiobutton(self, text="Myspace", variable = rchoice, value = 'myspace').pack(fill = X)
- ttk.Radiobutton(self, text="TypeWriter", variable = rchoice, value = 'typewriter').pack(fill = X)
- ttk.Radiobutton(self, text="Twitter", variable = rchoice, value = 'twitter').pack(fill = X)
- ttk.Radiobutton(self, text="Quantum Computers", variable = rchoice, value = 'Quantum Computers', command = rightanswer).pack(fill = X)
- ttk.Radiobutton(self, text="All of The Above", variable = rchoice, value = 'all').pack(fill = X)
- ttk.Radiobutton(self, text="None of The Above", variable = rchoice, value = 'none').pack(fill = X)
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page2))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page4),submit(str(rchoice.get()))])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 3)
- progressbar.pack()
- class Page4(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 4", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="What kind of Hardware device is a Keyboard?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- entry = ttk.Entry(self, text="Question 4", font=LARGE_FONT)
- entry.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page3))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page5),submit(entry.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 4)
- progressbar.pack()
- class Page5(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 5", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="What kind of Hardware device is a Speaker?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- entry = ttk.Entry(self, text="Question 5", font=LARGE_FONT)
- entry.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page4))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page6),submit(entry.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 5)
- progressbar.pack()
- class Page6(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 6", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="What is the truest definition of copyright laws?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- combobox = ttk.Combobox(self)
- combobox.config(width = 50, values = ('Laws in place to safeguard legal intellectual property.', 'Laws to enable the copying of rights', 'Laws that stop you from making original work',
- 'Laws that only allowing copying correct information', 'All of the Above'))
- combobox.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page5))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page7),submit(combobox.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 6)
- progressbar.pack()
- class Page7(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 7", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="Software developers who develop custom applications :", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- r2choice = StringVar()
- ttk.Radiobutton(self, text="should bother briefly listening to the customer.", variable = r2choice, value = 'brief').pack(fill = X)
- ttk.Radiobutton(self, text="do not need to care about the customer.", variable = r2choice, value = 'dont care').pack(fill = X)
- ttk.Radiobutton(self, text="must know their customers' expectations and requirements precisely.", variable = r2choice, value = 'listen', command = rightanswer).pack(fill = X)
- ttk.Radiobutton(self, text="must ignore the customer, regardless of their input.", variable = r2choice, value = 'ignore').pack(fill = X)
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page6))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page8),submit(str(r2choice.get()))])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 7)
- progressbar.pack()
- class Page8(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 8", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text= "Gradually introducing a new system onto a site is a feature of which method of conversion?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- combobox = ttk.Combobox(self)
- combobox.config( values = ('Parallel', 'Direct cut-over', 'Phased', 'All of the Above'))
- combobox.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page7))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page9),submit(combobox.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 8)
- progressbar.pack()
- class Page9(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 9", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="Software that simultaneously simulates a specified number of users entering data into an application is an example of what?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- combobox = ttk.Combobox(self)
- combobox.config( values = ('Case utilities', 'Software tools', 'Case tools', 'Virtual box', 'Virtual machine', 'Utility tools'))
- combobox.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page8))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit", command=lambda:[controller.show_frame(Page10),submit(combobox.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 9)
- progressbar.pack()
- class Page10(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label1 = ttk.Label(self, text="Question 10", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(self, text="What does the acronym RAM stand for?", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- entry = ttk.Entry(self, text="Question 10", font=LARGE_FONT)
- entry.pack()
- buttonprev = ttk.Button(self, text="Previous", command=lambda: controller.show_frame(Page9))
- buttonprev.pack()
- button2 = ttk.Button(self, text="Submit",
- command=lambda:[controller.show_frame(PageFinish),submit(entry.get())])
- button2.pack()
- progressbar = ttk.Progressbar(self, orient = HORIZONTAL, length = 200)
- progressbar.config(mode = 'determinate', maximum = 10.0, value = 10)
- progressbar.pack()
- class PageFinish(tk.Frame):
- def __init__(self, parent, controller):
- ttk.Frame.__init__(self, parent)
- label = ttk.Label(self, text="You Finished!", font=LARGE_FONT)
- label.pack(pady=10,padx=10)
- label = ttk.Label(self, text="Go Back to Home to Find out your score, we hope you aced it!", font=LARGE_FONT)
- label.pack(pady=10,padx=10)
- buttonprev = ttk.Button(self, text="Home", command=lambda:[quizfin()])
- buttonprev.pack()
- #Functions
- def toggle_timecount():
- global tog_timecount
- tog_timecount = 1
- #Used to Determine the customisable counter as well as general time management
- #Should be noted 59 seconds is used because function begins counting every second at 00 instead of 01
- def timecount(minutes):
- global timeout
- global tog_timecount
- if tog_timecount > 0:
- print("ahhh")
- start = time.time()
- time.clock()
- sec_elapsed = 0
- min_elapsed = 0
- while min_elapsed < minutes:
- sec_elapsed = time.time() - start
- print("minutes count:",min_elapsed,"loop cycle time: %f, seconds count: %02d" % (time.clock() , sec_elapsed))
- time.sleep(1)
- if sec_elapsed > 59:
- min_elapsed += 1
- start = time.time()
- print("Times Up!")
- timeout = 1
- tog_timecount = 0
- def quiz():
- root.iconify()
- th1 = threading.Thread(target=QuizApp(),)
- th2 = threading.Thread(target=timecount, args=(int(countmin.get()),))
- th1.start()
- th2.start()
- def quizfin():
- root.deiconify()
- def rightanswer():
- global rightans
- print("ERROR 2018: Something went wrong when getting response, manually checking...")
- rightans = 1
- def submit(response):
- global timeout
- global score
- global countans
- global rightans
- if rightans == 1:
- rightans = 0
- submit("Manual Correct")
- else:
- countans += 1
- if countans == 1:
- answer = qz["How many stages are there in the Structured Approach?"]
- if countans == 2:
- answer = qz["What is a device that provides input into a control system called?"]
- if countans == 3:
- answer = qz["Which of the Following is an example of an emerging technology?"]
- if countans == 4:
- answer = qz["What kind of Hardware device is a Keyboard?"]
- if countans == 5:
- answer = qz["What kind of Hardware device is a Speaker?"]
- if countans == 6:
- answer = qz["What is the truest definition of copyright?"]
- if countans == 7:
- answer = qz["Software developers who develop custom applications :"]
- if countans == 8:
- answer = qz["Gradually introducing a new system onto a site is a feature of which method of conversion?"]
- if countans == 9:
- answer = qz["Software that simultaneously simulates a specified number of users entering data into an application is an example of what?"]
- if countans == 10:
- answer = qz["What does the acronym RAM stand for?"]
- if timeout == 0:
- if response.lower() == str(answer).lower():
- score += 1
- print("Correct.")
- else:
- print("Sorry " + response + " Is WRONG, for question "+ str(countans) + " correct answer is " + str(answer))
- print("You Currently have a score of " + str(score))
- if countans == 10:
- lbscore = ttk.Label(tab1, text= "Correct: " + str(score), font =('Courier', 24, 'bold'), justify = CENTER, foreground = '#23fc8c', background = '#262626')
- lbscore.pack(pady=10,padx=10)
- if __name__ == '__main__':
- #Creation of Root Window
- root = Tk()
- root.resizable(False, False)
- root.iconbitmap(default='icon.ico')
- root.wm_title("Bugz - Home")
- #Variables
- countmin = IntVar()
- #Properties of Root Window
- root.configure(background='#262626')
- notebook = ttk.Notebook(root)
- notebook.pack()
- tab1 = tk.Frame(notebook)
- tab1.config(background = '#262626')
- tab2 = tk.Frame(notebook)
- tab2.config(background = '#262626')
- #Root Window Widgets
- notebook.add(tab1, text = 'Quiz')
- notebook.add(tab2, text = 'Help')
- panedwindow = ttk.Panedwindow(tab2, orient = HORIZONTAL)
- panedwindow.pack(fill = BOTH, expand = True)
- #Home Widgets
- lbtitle = ttk.Label(tab1, text = "Error")
- lbtitle.config(text= "Bugz HSC SDD Course Quiz", justify = CENTER, foreground = '#3f31e0', background = '#262626', font =('Courier', 24, 'bold'))
- lbtitle.pack(pady=10,padx=10)
- cbcount = tk.Checkbutton(tab1, text = 'In-Test Counter', justify = CENTER, foreground = '#3f31e0', background = '#262626', font =LARGE_FONT, command = toggle_timecount)
- cbcount.pack(pady=10,padx=10)
- lbtime = ttk.Label(tab1, text = "Error")
- lbtime.config(text= "Time Limit (Minutes):", justify = CENTER, foreground = '#3f31e0', background = '#262626', font =LARGE_FONT)
- lbtime.pack(pady=1,padx=1)
- sbcount = Spinbox(tab1, from_ = 1, to = 20, textvariable = countmin)
- sbcount.pack(pady=1,padx=1)
- countmin.get()
- btquiz = ttk.Button(tab1, text = "Error")
- btquiz.config(text = "Begin Quiz", compound = CENTER, command = quiz)
- btquiz.pack(pady=10,padx=10)
- #Help Widgets
- lbtitle = ttk.Label(tab2, text = "Error")
- lbtitle.config(text= "Bugz HSC SDD Course Quiz", justify = CENTER, foreground = '#3f31e0', background = '#262626', font =('Courier', 24, 'bold'))
- lbtitle.pack(pady=10,padx=10)
- frame1 = ttk.Frame(panedwindow, height = 100, width = 150, relief = SUNKEN)
- frame1.pack()
- frame2 = ttk.Frame(panedwindow, height = 400, width = 400, relief = SUNKEN, padding = (30, 15))
- frame2.pack()
- panedwindow.add(frame1, weight = 3)
- panedwindow.add(frame2, weight = 8)
- examplegif = PhotoImage(file = 'Key.gif')
- labelimg = ttk.Label(frame2, image = examplegif)
- labelimg.pack(fill = BOTH, expand = True)
- label1 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label1.pack(pady=10,padx=10)
- label2 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- label3 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label3.pack(pady=10,padx=10)
- label4 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- label4 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label2.pack(pady=10,padx=10)
- label5 = ttk.Label(frame1, text="1. Question Number", font=LARGE_FONT)
- label5.pack(pady=10,padx=10)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement