from tkinter import *
import tkinter.font as font
import csv
fichier = open("tableau_periodique.csv", "r")
lecteur = csv.DictReader(fichier,delimiter=',')
#Création des fonctions
def fen_info():
fenetre_info = Canvas(fen, width=500, height=257, bg = "white", highlightthickness=5,highlightbackground=atome['bg'])
fenetre_info.place(x=600, y = 0)
taille=font.Font(size=15)
bouton1=Button(fen,text="-Informations sur l'atome-",width=45,height=5,font=taille)
bouton1['font'] = taille
bouton1.place(x=603,y=3)
bouton2=Button(fen,text="-Ajouter à la création d'une molécule-",width=45,height=5,font=taille)
bouton2['font'] = taille
bouton2.place(x=603,y=134)
#création fenetre
fen = Tk()
fen.title("Teableau périodique des éléments")
fen.geometry("1260x720")
fen.minsize(1260,720)
fen.maxsize(1260,720)
fen.iconbitmap("molecule.ico")
fen.config(bg = "white")
#création du tableau
width = 3
height = 2
xx = 0
yy = 40
hydrogene = Button(fen, text="H",width=width, height=height, bg = "grey",command=fen_info)
hydrogene.place(x=0,y=0)
helium = Button(fen, width=width, height=height, bg = "cyan", text="He",command=fen_info)
helium.place(x=510,y=0)
for ligne in lecteur:
if ligne["famille"] == "Gaz rares":
atome = Button(fen, width=width, height=height, bg = "cyan", text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
xx += 30
elif ligne["famille"] == "Métaux alcalins":
atome = Button(fen, text=ligne["symbole"],width=width, height=height, bg = "#FF5733",command=fen_info)
atome.place(x=xx,y=yy)
xx += 30
elif ligne["famille"] == "Métaux alcalino-ferreux":
atome = Button(fen,text=ligne["symbole"], width=width, height=height, bg = "yellow",command=fen_info)
atome.place(x=xx,y=yy)
if ligne["symbole"] == "Mg" or ligne["symbole"] == "Be":
xx += 330
else:
xx += 30
elif ligne["famille"] == "Non métaux":
atome = Button(fen, width=width, height=height, bg = "green",text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
xx += 30
elif ligne["famille"] == "Métaux de transition":
if ligne["symbole"] == "Hf" or ligne["symbole"] == "Rf":
xx -= 420
atome = Button(fen, width=width, height=height, bg = "#FF46A5",text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
xx += 30
elif ligne["famille"] == "Lanthanides":
if ligne["symbole"] == 'La':
for i in range(2):
asterix = Button(fen, width=width, height=height, bg = "#FF9146",text="*")
asterix.place(x=xx,y=yy)
yy += 100
yy -= 200
yy += 100
xx += 30
atome = Button(fen, width=width, height=height, bg = "#FF9146", text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
yy -= 100
elif ligne["famille"] == "Actinides":
if ligne["symbole"] == 'Ac':
for i in range(2):
asterix2 = Button(fen, width=width, height=height, bg = "#AE46FF",text="**")
asterix2.place(x=xx,y=yy)
yy += 100
yy -= 200
yy += 100
xx += 30
atome = Button(fen, width=width, height=height, bg = "#AE46FF",text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
yy -= 100
elif ligne["famille"] == "Métaux pauvres":
atome = Button(fen, width=width, height=height, bg = "blue",text=ligne["symbole"],command=fen_info)
atome.place(x=xx,y=yy)
xx += 30
if xx >= 540:
yy += 40
xx = 0
fen.mainloop()
fichier.close()
Je sais qu'il est tres long, voir trop mais ce n'est pas le sujet.
Pour la fonction fen_info, je souhaiterai créer une boucle qui permet de changer la couleur de highlightthickness en fonction de la couleur définie pour chaque atome.
J'espere que c'est clair sinon voici une photo de ce qu'il doit se passer.
Merci d'avance
- Edité par ProbbyistProbbyist 2 mars 2021 à 17:04:24
Personnellement, je passerai par un dictionnaire "Couleurs_Famille_Atomes" et, lors de l'appel de la fonction, il faut passer en paramètre la valeur concernée et modifier la fonction "fen_info" en conséquence.
En espérant que tu as compris, Python apporte beaucoup plus que des boucles ou des conditions 'if elif else"
- Edité par Anonyme 2 mars 2021 à 20:03:34
Changer couleur Canvas en fonction de la ligne csv
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
PB68