Skip to content
Snippets Groups Projects
Commit 89abcd85 authored by Paul Chevalier's avatar Paul Chevalier
Browse files

multithreading ne marche pas

parent 7659bf2b
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -43,7 +43,7 @@ def charger_menu():
print(f"Temps d'exécution : {-(temps - tmp):.6f} secondes")
a.mainloop() # Lancer l'application principale
a.destroy()
# --- Lancer le chargement en arrière-plan ---
thread = threading.Thread(target=charger_menu)
......
import os
import sys
import time
import threading
import os
import sys
from tkinter import Tk, Label
from PIL import Image, ImageTk # Installer Pillow si nécessaire : pip install pillow
# --- Création du Splash Screen ---
splash = Tk()
splash.overrideredirect(True) # Enlever la barre de titre
# Charger l'image
image = Image.open("LogoSymbole_canard.png")
photo = ImageTk.PhotoImage(image)
# Définir la taille et centrer
screen_width = splash.winfo_screenwidth()
screen_height = splash.winfo_screenheight()
img_width, img_height = image.size
x_pos = (screen_width - img_width) // 2
y_pos = (screen_height - img_height) // 2
splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}")
# Afficher l'image
label = Label(splash, image=photo)
label.pack()
splash.update() # Mise à jour de l'affichage
base_dir = os.path.dirname(os.path.abspath(__file__))
dossier_path = os.path.join(base_dir,'Code_objets')
dossier_path = os.path.join(base_dir,'Objet')
sys.path.append(dossier_path)
import Menu
a = Menu.App()
import menu
a = menu.App()
splash.destroy()
a.mainloop()
......@@ -3,20 +3,17 @@ from PIL import Image, ImageTk
import threading
import time
# Fonction pour afficher le splash screen
def show_splash():
global splash # Garder une référence à la fenêtre
global splash, photo
splash = tk.Tk()
splash.overrideredirect(True) # Enlever la barre de titre
splash.overrideredirect(True)
# Charger l'image
image = Image.open("LogoSymbole_canard.png") # Remplace par ton logo
image = Image.open("LogoSymbole_canard.png")
photo = ImageTk.PhotoImage(image)
# Définir la taille et centrer
# Centrer la fenêtre
screen_width = splash.winfo_screenwidth()
screen_height = splash.winfo_screenheight()
img_width, img_height = image.size
......@@ -24,40 +21,41 @@ def show_splash():
y_pos = (screen_height - img_height) // 2
splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}")
# Afficher l'image
label = tk.Label(splash, image=photo)
label.image = photo # Évite la suppression de l'image par le garbage collector
label.pack()
splash.update()
splash.mainloop() # Garde la fenêtre active jusqu'à ce qu'on la ferme
# Lancer le thread du programme principal
global main_thread
main_thread = threading.Thread(target=load_main_program, daemon=True)
main_thread.start()
# Fonction pour charger le programme principal
def load_main_program():
time.sleep(3) # Simule un chargement
# Vérifier périodiquement si le programme principal est chargé
splash.after(100, check_thread)
# Fermer l'écran de chargement
splash.destroy()
splash.mainloop()
def load_main_program():
"""Charge le programme principal (menu.App), sans interaction directe avec Tkinter."""
import os
import sys
import sys
base_dir = os.path.dirname(os.path.abspath(__file__))
dossier_path = os.path.join(base_dir,'Objet')
dossier_path = os.path.join(base_dir, 'Objet')
sys.path.append(dossier_path)
import menu
global app
app = menu.App() # Instanciation de l'application
def check_thread():
"""Vérifie si le thread principal a fini de charger le programme."""
if not main_thread.is_alive():
splash.destroy() # Fermer le splash
app.mainloop() # Lancer l'application principale dans le thread principal
else:
splash.after(100, check_thread) # Vérifier à nouveau après 100 ms
# Lancer le programme principal ici
a = menu.App()
a.mainloop()
# Démarrer le splash screen dans un thread
splash_thread = threading.Thread(target=show_splash)
splash_thread.start()
# Charger le programme principal dans un autre thread
main_thread = threading.Thread(target=load_main_program)
main_thread.start()
# Démarrer le splash screen dans le thread principal
show_splash()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment