0% found this document useful (0 votes)
4 views4 pages

Universitar Orar App in Tkinter

The document describes a university schedule application built using Tkinter in Python. It allows users to add courses with details such as course name, professor, type, day, start time, and end time, and provides functionalities to save the schedule as a JSON file or print it as a PDF. The application includes a graphical interface with color-coded representations for different professors and course types.

Uploaded by

liviucalistru95
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Universitar Orar App in Tkinter

The document describes a university schedule application built using Tkinter in Python. It allows users to add courses with details such as course name, professor, type, day, start time, and end time, and provides functionalities to save the schedule as a JSON file or print it as a PDF. The application includes a graphical interface with color-coded representations for different professors and course types.

Uploaded by

liviucalistru95
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import tkinter as tk

from tkinter import messagebox, filedialog


from tkinter import ttk
from [Link] import letter
from [Link] import canvas
import json

class Curs:
def __init__(self, nume, profesor, tip, zi, ora_inceput, ora_sfarsit):
[Link] = nume
[Link] = profesor
[Link] = tip
[Link] = zi
self.ora_inceput = ora_inceput
self.ora_sfarsit = ora_sfarsit

class AplicatieOrar:
def __init__(self, root):
[Link] = root
[Link]("Orar Universitar")
[Link](False, False)

[Link] = []
self.profesor_culori = {
"Prof. A": "lightblue",
"Prof. B": "lightgreen",
"Prof. C": "lightyellow",
"Prof. D": "lightcoral",
"Prof. E": "lightpink"
}
self.tip_culori = {
"Curs": "lightgray",
"Seminar": "lightcyan",
"Laborator": "lightgoldenrod"
}

# Mapping course names to professors


self.course_professor_mapping = {
"Curs 1": "Prof. A",
"Curs 2": "Prof. B",
"Seminar 1": "Prof. C",
"Laborator 1": "Prof. D",
"Laborator 2": "Prof. E"
}

# Label cu denumirea universității


self.label_universitate = [Link](root, text="Universitatea Vasile
Alecsandri", font=("Arial", 16))
self.label_universitate.grid(row=0, column=0, columnspan=4, pady=10,
sticky='nsew')

# Etichete și câmpuri
self.create_widgets()

# Canvas pentru a desena orarul


[Link] = [Link](root, width=600, height=400, bg="white")
[Link](row=8, column=0, columnspan=4, sticky='nsew')

# Configurarea grilei pentru a se adapta la dimensiuni


for i in range(5):
root.grid_columnconfigure(i, weight=1)
root.grid_rowconfigure(8, weight=1)

def create_widgets(self):
[Link]([Link], text="Nume Curs:").grid(row=1, column=0, sticky='e')
self.txt_nume = [Link]([Link],
values=list(self.course_professor_mapping.keys()), state="readonly")
self.txt_nume.grid(row=1, column=1, sticky='ew')
self.txt_nume.bind("<<ComboboxSelected>>", self.on_course_selected)

[Link]([Link], text="Profesor:").grid(row=2, column=0, sticky='e')


self.profesor_combo = [Link]([Link],
values=list(self.profesor_culori.keys()), state="readonly")
self.profesor_combo.grid(row=2, column=1, sticky='ew')

[Link]([Link], text="Tip Curs:").grid(row=3, column=0, sticky='e')


self.var_tip = [Link](value="Curs")
[Link]([Link], text="Curs", variable=self.var_tip,
value="Curs").grid(row=3, column=1, sticky='w')
[Link]([Link], text="Seminar", variable=self.var_tip,
value="Seminar").grid(row=3, column=1, sticky='e')
[Link]([Link], text="Laborator", variable=self.var_tip,
value="Laborator").grid(row=3, column=1, sticky='se')

[Link]([Link], text="Zi:").grid(row=4, column=0, sticky='e')


self.txt_zi = [Link]([Link])
self.txt_zi.grid(row=4, column=1, sticky='ew')

[Link]([Link], text="Ora Început:").grid(row=5, column=0, sticky='e')


self.ora_inceput_combo = [Link]([Link],
values=self.create_time_slots())
self.ora_inceput_combo.grid(row=5, column=1, sticky='ew')

[Link]([Link], text="Ora Sfârșit:").grid(row=6, column=0, sticky='e')


self.ora_sfarsit_combo = [Link]([Link],
values=self.create_time_slots())
self.ora_sfarsit_combo.grid(row=6, column=1, sticky='ew')

# Butoane
button_frame = [Link]([Link])
button_frame.grid(row=7, column=0, columnspan=4, pady=10, sticky='ew')

[Link](button_frame, text="Adaugă Curs",


command=self.adauga_curs).grid(row=0, column=0, padx=5)
[Link](button_frame, text="Salvează",
command=self.salveaza_orar).grid(row=0, column=1, padx=5)
[Link](button_frame, text="Printare", command=[Link]).grid(row=0,
column=2, padx=5)
[Link](button_frame, text="Editare",
command=self.editare_curs).grid(row=0, column=3, padx=5)
[Link](button_frame, text="Ieșire", command=[Link]).grid(row=0,
column=4, padx=5)

def on_course_selected(self, event):


course_name = self.txt_nume.get()
professor_name = self.course_professor_mapping.get(course_name)
self.profesor_combo.set(professor_name if professor_name else "")
def create_time_slots(self):
time_slots = []
for hour in range(8, 21): # Interval de la 8:00 la 20:00
time_slots.append(f"{hour}:00")
time_slots.append(f"{hour}:30")
return time_slots

def adauga_curs(self):
curs_nou = Curs(
self.txt_nume.get(),
self.profesor_combo.get(),
self.var_tip.get(),
self.txt_zi.get(),
self.ora_inceput_combo.get(),
self.ora_sfarsit_combo.get()
)
[Link](curs_nou)
self.actualizeaza_orar()
self.clear_fields()

def actualizeaza_orar(self):
[Link]("all") # Șterge toate formele existente

for curs in [Link]:


start_hour = int(curs.ora_inceput.split(":")[0])
start_minute = int(curs.ora_inceput.split(":")[1])
end_hour = int(curs.ora_sfarsit.split(":")[0])
end_minute = int(curs.ora_sfarsit.split(":")[1])

# Calculăm poziția în funcție de oră


y_start = (start_hour - 8) * 40 + (start_minute // 30) * 20
y_end = (end_hour - 8) * 40 + (end_minute // 30) * 20

# Culorile pentru dreptunghiuri


profesor_color = self.profesor_culori.get([Link], "white")
tip_color = self.tip_culori.get([Link], "lightgray")

# Desenăm dreptunghiul pentru intervalul orar


[Link].create_rectangle(50, y_start, 550, y_end, fill=tip_color,
outline="black")

# Adăugăm text pentru profesor, interval orar și tip curs


[Link].create_text(100, (y_start + y_end) // 2,
text=[Link], anchor="w", fill=profesor_color)
[Link].create_text(300, (y_start + y_end) // 2, text=f"{[Link]}
({curs.ora_inceput} - {curs.ora_sfarsit})", anchor="center")
[Link].create_text(500, (y_start + y_end) // 2, text=f"{[Link]}
- {'Săptămână impară' if self.is_odd_week([Link]) else 'Săptămână pară'}",
anchor="e", fill="black")

def is_odd_week(self, week_number):


try:
week = int(week_number)
return week % 2 != 0
except ValueError:
return False

def clear_fields(self):
self.txt_nume.set('') # Reset the ComboBox
self.profesor_combo.set('') # Reset the ComboBox
self.var_tip.set("Curs") # Reset radiobutton
self.txt_zi.delete(0, [Link])
self.ora_inceput_combo.set('') # Reset the ComboBox
self.ora_sfarsit_combo.set('') # Reset the ComboBox

def salveaza_orar(self):
filename = [Link](defaultextension=".json",
filetypes=[("JSON files", "*.json")])
if filename:
with open(filename, 'w') as f:
[Link]([curs.__dict__ for curs in [Link]], f)
[Link]("Info", "Orarul a fost salvat.")

def printare(self):
filename = [Link](defaultextension=".pdf",
filetypes=[("PDF files", "*.pdf")])
if filename:
self.generare_pdf(filename)
[Link]("Info", f"Orarul a fost salvat ca PDF: {filename}")

def generare_pdf(self, filename):


c = [Link](filename, pagesize=letter)
width, height = letter

[Link](100, height - 50, "Orar Universitar")


[Link](100, height - 70, "Zi: " + self.txt_zi.get())

# Adăugăm cursurile în PDF


y = height - 100
for curs in [Link]:
[Link](100, y, f"{[Link]} - {[Link]} - {[Link]}
({curs.ora_inceput} - {curs.ora_sfarsit})")
y -= 20

[Link]()

def editare_curs(self):
[Link]("Info", "Funcționalitate de editare nu este
implementată încă.")

if __name__ == "__main__":
root = [Link]()
app = AplicatieOrar(root)
[Link]()

You might also like