0% found this document useful (0 votes)
6 views1 page

PRJ ph2

This document contains a Python script that uses Tkinter to create a GUI for displaying images based on pH levels. It categorizes the pH input into acidic, neutral, or basic and shows the corresponding image. The images are loaded from a dictionary and resized for display in the application.

Uploaded by

enamichak00
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)
6 views1 page

PRJ ph2

This document contains a Python script that uses Tkinter to create a GUI for displaying images based on pH levels. It categorizes the pH input into acidic, neutral, or basic and shows the corresponding image. The images are loaded from a dictionary and resized for display in the application.

Uploaded by

enamichak00
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
You are on page 1/ 1

import tkinter as tk

from tkinter import Label


from PIL import Image, ImageTk

# Dictionnaire des images


images = {
"acide": "sol_acide.jpg",
"neutre": "sol_neutre.jpg",
"basique": "sol_basique.jpg"
}

def afficher_image():
ph = float(entry.get())

if ph < 6.5:
categorie = "acide"
elif 6.5 <= ph <= 7.5:
categorie = "neutre"
else:
categorie = "basique"

img = Image.open(images[categorie])
img = img.resize((300, 300))
img = ImageTk.PhotoImage(img)

label_img.config(image=img)
label_img.image = img
label_text.config(text=f"Sol {categorie} (pH = {ph})")

# Création de la fenêtre
root = tk.Tk()
root.title("Affichage de l'image selon le pH")

entry = tk.Entry(root)
entry.pack()

btn = tk.Button(root, text="Afficher", command=afficher_image)


btn.pack()

label_text = Label(root, text="Entrez un pH")


label_text.pack()

label_img = Label(root)
label_img.pack()

root.mainloop()

You might also like