цуканов12.py 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import tkinter as tk
  2. from tkinter import messagebox
  3. class QuizApp:
  4. def __init__(self, root):
  5. self.root = root
  6. self.root.title("Модели построения информационных систем")
  7. self.questions = [
  8. {
  9. 'question': 'Какая из моделей описывает структуру данных в информационной системе?',
  10. 'options': ['Модель процессов', 'Модель данных', 'Модель взаимодействия', 'Модель организационной структуры'],
  11. 'correct_option': 1
  12. },
  13. {
  14. 'question': 'Классическая модель, которая отображает процессы и их последовательность — это...',
  15. 'options': ['Модель данных', 'Модель процессов', 'Модель взаимодействия', 'Модель организационной структуры'],
  16. 'correct_option': 1
  17. }
  18. ]
  19. self.current_q_index = 0
  20. self.correct_answers = 0
  21. self.create_scene1()
  22. def clear_screen(self):
  23. for widget in self.root.winfo_children():
  24. widget.destroy()
  25. def create_scene1(self):
  26. self.clear_screen()
  27. tk.Label(self.root, text="Добро пожаловать в игру: 'Модели построения информационных систем'!", font=('Arial', 16)).pack(pady=20)
  28. start_button = tk.Button(self.root, text="Начать игру", command=self.scene2)
  29. start_button.pack(pady=20)
  30. def scene2(self):
  31. self.clear_screen()
  32. if self.current_q_index >= len(self.questions):
  33. self.show_results()
  34. return
  35. q = self.questions[self.current_q_index]
  36. tk.Label(self.root, text=f"Вопрос {self.current_q_index + 1}:", font=('Arial', 14)).pack(pady=10)
  37. tk.Label(self.root, text=q['question'], wraplength=600).pack(pady=10)
  38. self.var = tk.IntVar()
  39. for idx, option in enumerate(q['options']):
  40. rb = tk.Radiobutton(self.root, text=option, variable=self.var, value=idx+1, font=('Arial', 12))
  41. rb.pack(anchor='w')
  42. next_button = tk.Button(self.root, text="Ответить", command=self.check_answer)
  43. next_button.pack(pady=10)
  44. def check_answer(self):
  45. selected = self.var.get()
  46. correct = self.questions[self.current_q_index]['correct_option']
  47. is_correct = (selected == correct)
  48. if is_correct:
  49. self.correct_answers += 1
  50. self.show_feedback(is_correct)
  51. def show_feedback(self, is_correct):
  52. self.clear_screen()
  53. if is_correct:
  54. msg = "Правильно! Молодец."
  55. else:
  56. correct_option_idx = self.questions[self.current_q_index]['correct_option']
  57. correct_answer = self.questions[self.current_q_index]['options'][correct_option_idx - 1]
  58. msg = f"Неправильно. Правильный ответ: {correct_answer}."
  59. label = tk.Label(self.root, text=msg, font=('Arial', 14))
  60. label.pack(pady=20)
  61. next_button = tk.Button(self.root, text="Далее", command=self.next_question)
  62. next_button.pack(pady=10)
  63. def next_question(self):
  64. self.current_q_index += 1
  65. self.scene2()
  66. def show_results(self):
  67. self.clear_screen()
  68. result_text = f"Вы ответили правильно на {self.correct_answers} из {len(self.questions)} вопросов."
  69. tk.Label(self.root, text="Итоги", font=('Arial', 16, 'bold')).pack(pady=20)
  70. tk.Label(self.root, text=result_text, font=('Arial', 14)).pack(pady=10)
  71. restart_button = tk.Button(self.root, text="Заново", command=self.restart_game)
  72. restart_button.pack(pady=10)
  73. exit_button = tk.Button(self.root, text="Завершить", command=self.root.quit)
  74. exit_button.pack(pady=5)
  75. def restart_game(self):
  76. self.current_q_index = 0
  77. self.correct_answers = 0
  78. self.create_scene1()
  79. if __name__ == "__main__":
  80. root = tk.Tk()
  81. root.geometry("700x500")
  82. app = QuizApp(root)
  83. root.mainloop()