[go: up one dir, main page]

0% found this document useful (0 votes)
67 views3 pages

Import Pandas As PD

Python

Uploaded by

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

Import Pandas As PD

Python

Uploaded by

fanevaniorenana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import pandas as pd

import tkinter as tk

from tkinter import ttk

from PIL import Image, ImageTk

from docx import Document

import os

# Lire les données depuis le fichier Excel

df = pd.read_excel('pierres_precieuses.xlsx')

# Créer la fenêtre principale

root = tk.Tk()

root.title("Bibliothèque des Pierres Précieuses")

root.geometry("900x700")

root.configure(bg="#f5f5f5") # Background color

# Créer un cadre pour afficher les informations

frame = ttk.Frame(root, padding="20")

frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S), padx=20, pady=20)

frame.configure(style="TFrame")

# Style personnalisé

style = ttk.Style()

style.configure("TFrame", background="#f5f5f5")

style.configure("TLabel", background="#f5f5f5", font=("Helvetica", 16))

style.configure("TCombobox", font=("Helvetica", 14))

style.configure("TButton", font=("Helvetica", 14))

# Fonction pour afficher les informations d'une pierre

def afficher_pierre(pierre):

for widget in frame.winfo_children():


widget.destroy()

nom = pierre['Nom']

photo_path = pierre['Répertoire Photo']

docx_path = pierre['Répertoire docx']

# Afficher le nom

label_nom = ttk.Label(frame, text=nom, font=("Helvetica", 24, "bold"))

label_nom.grid(row=0, column=0, columnspan=2, pady=10, padx=10)

# Afficher la photo avec gestion d'erreurs

if os.path.exists(photo_path):

try:

img = Image.open(photo_path)

img = img.resize((250, 250), Image.LANCZOS)

photo = ImageTk.PhotoImage(img)

label_photo = ttk.Label(frame, image=photo)

label_photo.image = photo

label_photo.grid(row=1, column=0, pady=10, padx=10)

except Exception as e:

label_error = ttk.Label(frame, text=f"Erreur lors du chargement de l'image: {str(e)}",


font=("Arial", 14), foreground="red")

label_error.grid(row=1, column=0, pady=10, padx=10)

else:

label_no_photo = ttk.Label(frame, text="Photo non trouvée", font=("Arial", 14),


foreground="red")

label_no_photo.grid(row=1, column=0, pady=10, padx=10)

# Afficher le contenu DOCX avec gestion d'erreurs

if os.path.exists(docx_path):

try:

doc = Document(docx_path)
text_content = "\n\n".join([paragraph.text for paragraph in doc.paragraphs])

text_docx = tk.Text(frame, wrap='word', height=20, width=50, font=("Helvetica", 14), padx=10,


pady=10)

text_docx.insert(tk.END, text_content)

text_docx.grid(row=1, column=1, pady=10, padx=10)

text_docx.configure(state='disabled') # Rendre le texte non modifiable

except Exception as e:

label_error = ttk.Label(frame, text=f"Erreur lors du chargement du fichier DOCX: {str(e)}",


font=("Arial", 14), foreground="red")

label_error.grid(row=1, column=1, pady=10, padx=10)

else:

label_docx = ttk.Label(frame, text="Fichier DOCX non trouvé", font=("Arial", 14),


foreground="red")

label_docx.grid(row=1, column=1, pady=10, padx=10)

# Ajouter une liste déroulante pour sélectionner une pierre

pierres = df['Nom'].tolist()

combo = ttk.Combobox(root, values=pierres, font=("Helvetica", 14))

combo.grid(row=1, column=0, pady=10, padx=20)

combo.bind("<<ComboboxSelected>>", lambda e: afficher_pierre(df.loc[df['Nom'] ==


combo.get()].iloc[0]))

# Démarrer l'interface

root.mainloop()

You might also like