aboutsummaryrefslogtreecommitdiff
path: root/Semestr 3/pf/lista3/test.py
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
commitc5fcf7179a83ef65c86c6a4a390029149e518649 (patch)
treed29ffc5b86a0d257453cedcf87d91a13d8bf3b0d /Semestr 3/pf/lista3/test.py
parentf8a88b6a4aba1f66d04711a9330eaba49a50c463 (diff)
Duzy commit ze smieciami
Diffstat (limited to 'Semestr 3/pf/lista3/test.py')
-rw-r--r--Semestr 3/pf/lista3/test.py139
1 files changed, 0 insertions, 139 deletions
diff --git a/Semestr 3/pf/lista3/test.py b/Semestr 3/pf/lista3/test.py
deleted file mode 100644
index f9c78d9..0000000
--- a/Semestr 3/pf/lista3/test.py
+++ /dev/null
@@ -1,139 +0,0 @@
-import json
-from fix import *
-import tkinter as tk
-import random
-import time
-
-
-random.seed(time.time())
-HEIGHT = 700
-WIDTH = 800
-
-
-class Quiz():
- def __init__(self, questions):
- self.questions = dict()
- for question in questions:
- self.questions[question.question_number] = question
- self.first_question = 1
- self.asked_questions = []
- self.correct_answers = 0
- self.current_question = self.get_random_question()
-
- def get_question(self, nr):
- self.asked_questions.append(nr)
- self.current_question = self.questions[nr]
- return self.questions[nr]
-
- def get_random_question(self, unasked=True):
- question = random.choice(list(self.questions.values()))
- if unasked:
- while question.question_number in self.asked_questions:
- question = random.choice(list(self.questions.values()))
- self.asked_questions.append(question.question_number)
- self.current_question = question
- return question
-
- def reset(self):
- self.asked_questions = []
- self.correct_answers = 0
-
- def answer_question(self, question, answer):
- if answer == question.correct_answer:
- self.correct_answers += 1
- return question.correct_answer
-
-
-def begin_quiz(root):
- quiz = Quiz(get_answers_from_json())
-
- quiestion_frame = tk.Frame(root, bd=1)
- quiestion_frame.place(relx=0.05, rely=0.1, relwidth=0.9, relheight=0.7)
-
- question_label = tk.Label(
- quiestion_frame, text=quiz.current_question.str_without_answer(), font='Helvetica 12', wraplength=550, justify='left')
- question_label.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
-
- stats_frame = tk.Frame(root, bg='white', bd=5)
- stats_frame.place(relx=0.7, rely=0.85, relwidth=0.25, relheight=0.1)
-
- correct_label = tk.Label(stats_frame, text='Poprawne: 0', font=20)
- correct_label.place(relx=0.05, rely=0.15, relwidth=0.9, relheight=0.2)
-
- answered_label = tk.Label(stats_frame, text='Zadane: 1', font=20)
- answered_label.place(relx=0.05, rely=0.40, relwidth=0.9, relheight=0.2)
-
- wr_label = tk.Label(stats_frame, text='Procent dobrych: 0%', font=20)
- wr_label.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.2)
-
- answers_frame = tk.Frame(root, bg='white', bd=5)
- answers_frame.place(relx=0.05, rely=0.85, relheight=0.1, relwidth=0.60)
-
- answer_buttons = []
-
- def next_question(next_question_button):
- for button in answer_buttons:
- button.configure(bg='grey')
- next_question_button.place_forget()
- quiz.get_random_question()
- question_label.configure(
- text=quiz.current_question.str_without_answer())
- answered_label.configure(text=f"Zadanie: {len(quiz.asked_questions)}")
-
- next_question_button = tk.Button(
- answers_frame, bg='grey', text='Następne', font='Helvetica 18 bold', command=lambda: next_question(next_question_button))
-
- def answer_question(answer):
- quiz.answer_question(quiz.current_question, answer)
- correct = quiz.current_question.correct_answer
- if correct != answer:
- answer_buttons[answer].configure(bg='red')
- else:
- correct_label.configure(
- text=f"Poprawne: {quiz.correct_answers}")
- wr_label.configure(
- text="Procent dobrych: {:.2f}%".format(round((quiz.correct_answers/(len(quiz.asked_questions)) * 100.0), 2)))
- answer_buttons[correct].configure(bg='green')
- next_question_button.place(relx=0.525, relheight=0.9)
-
- buttonA = tk.Button(answers_frame, text='a', bg='grey',
- font='Helvetica 18 bold', command=lambda: answer_question(0))
- buttonA.place(relx=0.025, relwidth=0.1, relheight=0.9)
-
- buttonB = tk.Button(answers_frame, text='b', bg='grey',
- font='Helvetica 18 bold', command=lambda: answer_question(1))
- buttonB.place(relx=0.15, relwidth=0.1, relheight=0.9)
-
- buttonC = tk.Button(answers_frame, text='c', bg='grey',
- font='Helvetica 18 bold', command=lambda: answer_question(2))
- buttonC.place(relx=0.275, relwidth=0.1, relheight=0.9)
-
- buttonD = tk.Button(answers_frame, text='d', bg='grey',
- font='Helvetica 18 bold', command=lambda: answer_question(3))
- buttonD.place(relx=0.4, relwidth=0.1, relheight=0.9)
-
- answer_buttons += [buttonA, buttonB, buttonC, buttonD]
-
-
-def __main__():
- root = tk.Tk()
-
- canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
- canvas.pack()
-
- background_image = tk.PhotoImage(file='ktos.png')
- background_label = tk.Label(root, image=background_image)
- background_label.place(x=0, y=0, relwidth=1, relheight=1)
-
- def begin():
- button.place_forget()
- begin_quiz(root)
-
- button = tk.Button(root, text="Zacznij zabawę",
- font=40, command=begin)
- button.place(relx=0.5, rely=0.5, anchor='n')
-
- root.mainloop()
-
-
-__main__()