self.data = load_data()
self.classes = list(self.data.keys())
self.selected_class = None
self.current_student = None
self.create_main_menu()
def create_main_menu(self):
for widget in self.root.winfo_children():
widget.destroy()
tk.Label(self.root, text="NCHOFOU LCLASSE :", font=("Arial", 16)).pack(pady=10)
self.class_listbox = tk.Listbox(self.root, width=30, font=("Arial", 13))
for cls in self.classes:
self.class_listbox.insert('end', cls)
self.class_listbox.pack(pady=5)
btn_frame = tk.Frame(self.root)
btn_frame.pack(pady=10)
tk.Button(btn_frame, text="DKHL Lclasse", command=self.enter_class).pack(side="left", padx=5)
tk.Button(btn_frame, text="ZID Classe", command=self.add_class).pack(side="left", padx=5)
tk.Button(btn_frame, text="Statistiques", command=self.show_stats).pack(side="left", padx=5)
def add_class(self):
def save_class():
cls_name = entry.get().strip()
if cls_name and cls_name not in self.data:
self.data[cls_name] = {}
self.classes.append(cls_name)
save_data(self.data)
win.destroy()
self.create_main_menu()
else:
messagebox.showerror("Erreur", "Smiyat lclasse kayna aw fargha.")
win = tk.Toplevel(self.root)
win.title("ZID Classe")
tk.Label(win, text="3ti smiyat lclasse:").pack(pady=5)
entry = tk.Entry(win)
entry.pack(padx=5, pady=5)
tk.Button(win, text="Smi7", command=save_class).pack(pady=5)
def enter_class(self):
sel = self.class_listbox.curselection()
if not sel:
messagebox.showwarning("Selection", "Ikhtar lclasse.")
return
self.selected_class = self.classes[sel[0]]
self.class_students = self.data[self.selected_class]
self.open_classroom()
def open_classroom(self):
for widget in self.root.winfo_children():
widget.destroy()
tk.Label(self.root, text=f"CLASS: {self.selected_class}", font=("Arial", 14)).pack(pady=6)
tk.Button(self.root, text="ZID TELEMD", command=self.add_students).pack(pady=5)
self.info_lbl = tk.Label(self.root, text="DWIR 3la lclasse mn clavier.", fg="grey")
self.info_lbl.pack(pady=3)
self.current_student_lbl = tk.Label(self.root, text="", font=("Arial", 17, "bold"), fg="blue")
self.current_student_lbl.pack(pady=20)
self.feedback_lbl = tk.Label(self.root, text="", font=("Arial", 13))
self.feedback_lbl.pack(pady=10)
self.root.bind('<Key>', self.handle_key)
tk.Button(self.root, text="Statistiques", command=self.show_stats).pack(pady=3)
tk.Button(self.root, text="Rj3 lmenu", command=self.back_to_menu).pack(pady=3)
def add_students(self):
def save_students():
names = entry.get("1.0", "end").strip().splitlines()
for n in names:
n = n.strip()
if n and n not in self.class_students:
self.class_students[n] = {"participations": 0, "correct": 0, "wrong": 0, "points": 0}
save_data(self.data)
win.destroy()
self.open_classroom()
win = tk.Toplevel(self.root)
win.title("ZID TELEMD")
tk.Label(win, text="KTAB SMYAT TELEMD F KOL LINE:").pack(pady=3)
entry = tk.Text(win, width=30, height=8)
entry.pack(padx=4, pady=6)
tk.Button(win, text="Smi7", command=save_students).pack(pady=4)
def back_to_menu(self):
self.root.unbind('<Key>')
self.selected_class = None
self.current_student = None
self.create_main_menu()
def show_stats(self):
win = tk.Toplevel(self.root)
win.title(f"Stats - {self.selected_class if self.selected_class else 'Kolchi'}")
txt = tk.Text(win, width=60, height=25)
txt.pack()
if self.selected_class:
data = self.data[self.selected_class]
txt.insert('end', f"{'Tilmid':<20} | {'Chark':<6} | {'S7i7':<6} | {'Khata2':<6} | {'No9at':<6}\n")
txt.insert('end', "-"*60+'\n')
for name, stats in data.items():
txt.insert('end', f"{name:<20} | {stats['participations']:<6} | {stats['correct']:<6} | {stats['wrong']:<6} | {stats['points']:<6}\n")
else:
for cls in self.classes:
txt.insert('end', f"CLASS: {cls}\n")
data = self.data[cls]
for name, stats in data.items():
txt.insert('end', f"{name:<20} | {stats['participations']:<6} | {stats['correct']:<6} | {stats['wrong']:<6} | {stats['points']:<6}\n")
txt.insert('end', "\n")
def pick_student(self):
if not self.class_students:
self.current_student_lbl.config(text="MAKAYNCH TLAMD.", fg="red")
self.current_student = None
return
names = list(self.class_students.keys())
self.current_student = random.choice(names)
# Trace it:
self.class_students[self.current_student]["participations"] += 1
save_data(self.data)
self.current_student_lbl.config(text=self.current_student, fg="blue")
self.feedback_lbl.config(text="")
self.show_animation("Choisi!", "lime")
def show_animation(self, msg, color):
self.feedback_lbl.config(text=msg, fg=color)
self.root.after(1200, lambda: self.feedback_lbl.config(text=""))
def handle_key(self, event):
# Controls via letters:
key = event.char.lower()
if key == "a": # 'A' to pick random student
self.pick_student()
elif key == "p": # 'P' => +1 point, correct answer
self.add_point(True)
elif key == "m": # 'M' => -1 point, wrong answer
self.add_point(False)
elif key == "n": # 'N' => Pick next student (pass)
self.pick_student()
self.show_animation("Essayer un autre élève!", "orange")
elif key == "s": # 'S' to show stats
self.show_stats()
elif key == "r": # 'R' return to main (menu)
self.back_to_menu()
# You can add more key controls as you like...
def add_point(self, correct=True):
if not self.current_student:
self.feedback_lbl.config(text="Chi telemid lwl!", fg="grey")
return
stats = self.class_students[self.current_student]
if correct:
stats["points"] += 1
stats["correct"] += 1
self.show_animation("Bravo! Jawb S7i7 🎉", "green")
else:
stats["points"] -= 1
stats["wrong"] += 1
self.show_animation("Ghalat! Hssn menk.", "red")
save_data(self.data)
import tkinter as tk
from tkinter import messagebox
import random
import json
import os
DATA_FILE = "classes_data.json"
def load_data():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r", encoding="utf-8") as f:
return json.load(f)
return {}
def save_data(data):
with open(DATA_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
class ParticipationTool:
def init(self, root):
self.root = root
self.root.title("Outil Participation - Talamid")
Run the app
if name == "main":
root = tk.Tk()
tool = ParticipationTool(root)
root.mainloop()