|
| 1 | +from tkinter import* |
| 2 | +from PIL import ImageTk, Image |
| 3 | +import os |
| 4 | +import datetime as dt |
| 5 | +detailed_report = ["Question | Answer | Correct Answer | Points"] |
| 6 | +score = [] |
| 7 | +questions = ['How do you print "Hello" in Python?', |
| 8 | + 'A GUI window can be created in python with the _______ module', |
| 9 | + 'How do you pick a random item from a list called "my_list"?', |
| 10 | + 'An ___________ is a computer program that directly executes instructions written in a programming language', |
| 11 | + 'How do you destroy a tkinter window when root = Tk()?'] |
| 12 | +answers = ['print("Hello")', |
| 13 | + 'tkinter', |
| 14 | + 'random.choice(my_list)', |
| 15 | + 'interpreter', |
| 16 | + 'root.destroy()'] |
| 17 | + |
| 18 | +quests = len(questions) |
| 19 | +window = Tk() |
| 20 | +window.title('Welcome') |
| 21 | +window2 = Tk() |
| 22 | +window2.title('Setup') |
| 23 | +name_label = Label(window2, text='What is your name?') |
| 24 | +name_entry = Entry(window2, fg="Black", bg="Yellow", width=50) |
| 25 | +next_but = Button(window2, padx=14,pady=14,bd=4,bg='orange',command=lambda:contin2(),text="Next >>>",font=("Courier New",16,'bold')) |
| 26 | +window2.withdraw() |
| 27 | + |
| 28 | +window3 = Tk() |
| 29 | +window3.title('Ready?') |
| 30 | +question = Label(window3, text='Every correct question earns you a point. Every incorrect one gives none. Good Luck!') |
| 31 | +butt = Button(window3, padx=14,pady=14,bd=4,bg='orange',command=lambda:contin3(),text="Next >>>",font=("Courier New",16,'bold')) |
| 32 | +window3.withdraw() |
| 33 | +tim = str(dt.datetime.now()) |
| 34 | + |
| 35 | +def cont(): |
| 36 | + window.destroy() |
| 37 | + window2.update() |
| 38 | + window2.deiconify() |
| 39 | + name_label.pack() |
| 40 | + name_entry.pack() |
| 41 | + next_but.pack() |
| 42 | + window2.mainloop() |
| 43 | + |
| 44 | +def contin2(): |
| 45 | + nameee = str(name_entry.get()) |
| 46 | + window2.destroy() |
| 47 | + question = Label(window3, text=nameee+', Every correct question earns you a point. Every incorrect one gives none. Good Luck!') |
| 48 | + question.pack() |
| 49 | + butt.pack() |
| 50 | + window3.update() |
| 51 | + window3.deiconify() |
| 52 | + |
| 53 | +def contin3(): |
| 54 | + window3.withdraw() |
| 55 | + contin4() |
| 56 | + |
| 57 | +def contin4(): |
| 58 | + window4 = Tk() |
| 59 | + window4.title('Questions') |
| 60 | + question2 = Label(window4, text=questions[0]) |
| 61 | + |
| 62 | + score_label = Label(window4, text= 'Score:' + str(len(score))) |
| 63 | + answer_entry = Entry(window4, fg="Black", bg="Yellow", width=50) |
| 64 | + butt2 = Button(window4, padx=14,pady=14,bd=4,bg='orange',command=lambda:window4.quit(),text="Next >>>",font=("Courier New",16,'bold')) |
| 65 | + question2.pack() |
| 66 | + score_label.pack() |
| 67 | + answer_entry.pack() |
| 68 | + butt2.pack() |
| 69 | + window4.mainloop() |
| 70 | + if (answer_entry.get() == answers[0]): |
| 71 | + print("Correct!") |
| 72 | + |
| 73 | + score.append(0) |
| 74 | + else: |
| 75 | + print("Incorrect! The correct answer is " + answers[0]) |
| 76 | + |
| 77 | + answers.pop(0) |
| 78 | + questions.pop(0) |
| 79 | + window4.destroy() |
| 80 | + if (0 < len(questions)): |
| 81 | + contin3() |
| 82 | + else: |
| 83 | + window3.destroy() |
| 84 | + file = open(str(dt.datetime.now())+' report.txt', "w") |
| 85 | + namu = "Hello! This report has been autogenerated from the results of the quiz in PyQuiz "+str(tim)+ " Your score is "+str(len(score))+"/"+str(quests)+" Thank you for answering PyQuiz's Quiz! We hope to see you again!" |
| 86 | + file.write(namu) |
| 87 | + file.close() |
| 88 | +img = ImageTk.PhotoImage(Image.open("Greet.jpg")) |
| 89 | +panel = Label(window, image = img) |
| 90 | +panel.pack(side = "top", fill = "both", expand = "yes") |
| 91 | +button = Button(window,padx=14,pady=14,bd=4,bg='orange',command=lambda:cont(),text="Continue >>>",font=("Courier New",16,'bold')) |
| 92 | +button.pack() |
| 93 | +window.mainloop() |
0 commit comments