from tkinter import * from tkinter import ttk from tkinter import messagebox import requests, json, jaro, zipfile, os import tkinter as tk #Get the name from the web site parcourstup r = requests.get("https://ressource.parcoursup.fr/data/files.xml") name = r.content[102:135].decode() print(f"https://ressource.parcoursup.fr/data/{name}.zip") # Download the dataset if it doesn't already exist if not os.path.exists(name): r = requests.get(f"https://ressource.parcoursup.fr/data/{name}.zip") with open('data.zip', 'wb') as file: file.write(r.content) with zipfile.ZipFile('data.zip', 'r') as zip_ref: zip_ref.extractall() # Load database print("Loading database ...") with open(name, "r") as file: database = json.loads(file.read()) def get_formations(prompt: str): indices = [max([(jaro.jaro_winkler_metric(actual_word, word), index) for word, index in database["lexique"]["index"].items()], key=lambda x: x[0])[1] for actual_word in prompt.split()] return [f"{formation['nm']} - {list(formation['recS'].keys())[-1]}" for formation in database["formations"].values() if all([str(index) in formation["recW"] for index in indices])] #creation première fenetre window = Tk() def __init__(window): Tk.__init__(window) window.create_menu_bar() #personnalisation fenêtre window.title("Choix EDS") window.geometry("1080x720") window.minsize(480, 360) window.maxsize(1920, 1080) window.iconbitmap("assets/bitmap.ico") window.config() #Listbox/scrollbar #création scrollbar scrollbar = ttk.Scrollbar(window) listbox = tk.Listbox(window, yscrollcommand=scrollbar.set) scrollbar.config(command=listbox.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) listbox.pack(fill=tk.BOTH, expand=True) #CREATIONN DES FRAMES frame = ttk.Frame(listbox) highframe = ttk.Frame(frame) bottomframe = ttk.Frame(frame) #Création menu bar menubar = Menu(window) window.config(menu=menubar) menuabout = Menu(menubar,tearoff=0) menunon = Menu(menubar,tearoff=0) def msgabout(): messagebox.showinfo("Choix EDS - En savoir plus ...", "By Raphael et Elouan") def msgabout1(): messagebox.showinfo("Choix EDS - Code Source", "git : https://git.tipragot.fr/Naomana/Choix_Spe") def msgabout2(): for i in range (100): messagebox.showinfo("Choix EDS - Il fallait pas", "Je l'avais, dit, il ne faut pas clicker") menubar.add_cascade(label="A propos", menu=menuabout) menubar.add_cascade(label="Non", menu=menunon) menuabout.add_command(label="Code source", command=msgabout1) menuabout.add_command(label="En savoir plus...", command=msgabout) menunon.add_command(label="Ne pas toucher", command=msgabout2) #AJOUT ET AFFICHAGE DES ELEMENTS #affichagge image can = Canvas(highframe, width = 200 , height = 100) can.pack() Objet_Image = PhotoImage(file='assets/Logo.png') Image_Affichee = can.create_image(0,0, image = Objet_Image, anchor='nw') #ajouter le titre label_title = ttk.Label(highframe, text="Aide au choix des spécialités", font=("Arial", 31)) #afficher le titre label_title.pack(side=tk.TOP, pady=8) #ajouter la description label_subtitle = ttk.Label(highframe, text="Cette application est une assistance pour le choix des EDS et du parcours post BAC", font=("Arial", 16)) label_subtitle.pack() #ajouter un champ de texte int_prompt = ttk.Entry(highframe, font=("Arial", 16)) #afficher le champ de texte int_prompt.pack(side=LEFT, expand=YES, fill=X, pady=25) #ajouter un bouton #définir fonction du bouton prompt = "" def getEntry(*_): prompt = int_prompt.get() print(get_formations(prompt)) click_btn= PhotoImage(file='assets/Search_button.png') #Let us create a label for button event img_label= Label(image=click_btn) #Let us create a dummy button and pass the image button= Button(highframe, image=click_btn,command= getEntry, borderwidth=0) button.pack(side=RIGHT, pady=30) #creer bouton #assingner boutton entrée window.bind("", getEntry) #AFFICHAGE DES FRAMES #affichage frame haute highframe.pack(side=TOP) #affichage frame basse bottomframe.pack(side=BOTTOM) #afficher la frame frame.pack(fill=tk.BOTH) #TRAITER INFORMATION USER #Récupérer l'éntrée dans une variable #affichage dans la boucle main window.mainloop()