: importation de la librairie tkinter à unifier + codes à améliorer
#!/usr/bin/env python # -*- coding: utf-8 -*- # Programme sur le tableau périodique # MJ, Ba2 chimie 2010-2011 from tkinter import * from element_liste import * #sert à importer la liste présente dans l'autre fichier #création de la commande générale du boutton def elem(x): element=Tk() element.title("Proprietes") listbox=Listbox(element,height=10,width=40,fg="#070942") listbox.pack() #sert à ajuster la fenêtre listbox.insert(END) for item in tableau[x]: listbox.insert(END,item) quitter = Button(element,text='Quitter',command=element.destroy) quitter.pack(side=BOTTOM) mainloop() fen1=Tk() fen1.title("Tableau periodique") #création de la légende (site www.jchr.be/python/tkinter.htm) import tkinter sysdemenu=tkinter.Menu(fen1) def legende(): legend1= Tk() legend1.title("Légende") frame= Frame(legend1, height=200, width= 300) #frame ouvre une nouvelle fenêtre dans laquelle on peut insérer plusieurs widgets (ici des messages) autre = Message(legend1, text="Autres", width=300, font="Arial 15", bg="white") #font = taille et police autre.pack() metauxtransition= Message(legend1, text="Metaux de transition", width=300, font="Arial 15", bg="#FFCCCC") metauxtransition.pack() gazrare = Message(legend1, text="Gaz rares", width=300, font="Arial 15", bg="#00CCFF") gazrare.pack() nonmetaux= Message(legend1, text="Non metaux", width=300, font="Arial 15", bg="#00FF66") nonmetaux.pack() metauxalcalins= Message(legend1, text="Metaux alcalins", width=300, font="Arial 15", bg="#FF9900") metauxalcalins.pack() metauxalcalinoterreux= Message(legend1, text="Metaux alcalino terreux", width=300, font="Arial 15", bg="#FFFF33") metauxalcalinoterreux.pack() lanthanides= Message(legend1, text="Lanthanides", width=300, font="Arial 15", bg="#CCCC66") lanthanides.pack() actinides= Message(legend1, text="Actinides", width=300, font="Arial 15", bg="#FF3300") actinides.pack() metaux= Message(legend1, text="Metaux", width=300, font="Arial 15", bg="#9999FF") metaux.pack() frame.pack() mainloop() Menu=tkinter.Menu(sysdemenu) sysdemenu.add_cascade(label="Menu", menu=Menu) Menu.add_command(label="Legende", command = legende) Menu.add_command(label="Quitter", command=fen1.quit) #création des boutons du tableau bou_list=[] for item in tableau[1:]: bou=Button(fen1,text=item[1],command=lambda x=item[2]:elem(x),height=2,width=3,bg=item[6]) bou.grid(row=item[4],column=item[5]) #grid est utilisé pour classer les bouttons par rangée et colonne bou_list.append(bou) fen1.config(menu=sysdemenu) #création de la listbox au sommet (source:http://www.tkdocs.com/tutorial/grid.html) centre=Listbox(fen1) centre.grid(row=0,column=3,rowspan= 1,columnspan=8) centre.insert(END) for item in ["Nom:","Symbole:", "Numero atomique:","Masse molaire:","Ligne:","Colonne:","Couleur:"]: centre.insert(END,item) mainloop() fen1.destroy() fen1.mainloop()
Nécessite ce fichier de données :
tableau=[ ["Nom","symbole","Numero atomique","Masse atomique", "ligne","colonne","couleur"], ["Hydrogene","H",1, 1.00794,1,0,"white"], ["Helium", "He",2, 4.0026,1,17,"#00CCFF"], ["Lithium", "Li", 3, 6.9412,2,0,"#FF9900"], ["Beryllium","Be",4,9.012182,2,1,"#FFFF33"], ["Bore","B",5,10.811,2,12,"#00FF66"], ["Carbone","C",6,12.0107,2,13,"#00FF66"], ["Azote","N",7,14.00674,2,14,"#00FF66"], ["Oxygene","O",8,15.9994,2,15,"#00FF66"], ["Fluor","F",9,18.9984,2,16,"#00FF66"], ["Neon","Ne",10,20.1797,2,17,"#00CCFF"], ["Sodium","Na",11,22.9897,3,0,"#FF9900"], ["Magnesium","Mg",12,24.3050,3,1,"#FFFF33"], ["Aluminium","Al",13,26.9815,3,12,"#9999FF"], ["Silicium","Si",14,28.0855,3,13,"#00FF66"], ["Phosphore","P",15,30.973761,3,14,"#00FF66"], ["Soufre","S",16,32.066,3,15,"#00FF66"], ["Chlore","Cl",17,35.453,3,16,"#00FF66"], ["Argon","Ar",18,39.948,3,17,"#00CCFF"], ["Potassium","K",19,39.0963,4,0,"#FF9900"], ["Calcium","Ca",20,40.078,4,1,"#FFFF33"], ["Scandium","Sc",21,44.9559,4,2,"#FFCCCC"], ["Titane","Ti",22,47.867,4,3,"#FFCCCC"], ["Vanadium","V",23,50.9415,4,4,"#FFCCCC"], ["Chrome","Cr",24,51.9961,4,5,"#FFCCCC"], ["Manganese","Mn",25,54.9380,4,6,"#FFCCCC"], ["Fer","Fe",26,55.8457,4,7,"#FFCCCC"], ["Cobalt","Co",27,58.9332,4,8,"#FFCCCC"], ["Nickel","Ni",28,58.6934,4,9,"#FFCCCC"], ["Cuivre","Cu",29,63.546,4,10,"#FFCCCC"], ["Zinc","Zn",30,65.409,4,11,"#FFCCCC"], ["Gallium","Ga",31,69.723,4,12,"#9999FF"], ["Germanium","Ge",32,72.64,4,13,"#9999FF"], ["Arsenic","As",33,74.9216,4,14,"#00FF66"], ["Selenium","Se",34,78.96,4,15,"#00FF66"], ["Brome","Br",35,79.904,4,16,"#00FF66"], ["Krypton","Kr",36,83.798,4,17,"#00CCFF"], ["Rubidium","Rb",37,85.4678,5,0,"#FF9900"], ["Strontium","Sr",38,87.62,5,1,"#FFFF33"], ["Yttrium","Y",39,88.9059,5,2,"#FFCCCC"], ["Zirconium","Zr",40,91.224,5,3,"#FFCCCC"], ["Niobium","Nb",41,92.9063,5,4,"#FFCCCC"], ["Molybdene","Mo",42,95.94,5,5,"#FFCCCC"], ["Technetium","Tc",43,98,5,6,"#FFCCCC"], ["Ruthenium","Ru",44,101.07,5,7,"#FFCCCC"], ["Rhodium","Rh",45,102.9055,5,8,"#FFCCCC"], ["Palladium","Pd",46,106.42,5,9,"#FFCCCC"], ["Argent","Ag",47,107.8682,5,10,"#FFCCCC"], ["Cadmium","Cd",48,112.411,5,11,"#FFCCCC"], ["Indium","In",49,114.818,5,12,"#9999FF"], ["Etain","Sn",50,118.710,5,13,"#9999FF"], ["Antimoine","Sb",51,121.760,5,14,"#9999FF"], ["Tellure","Te",52,127.60,5,15,"#00FF66"], ["Iode","I",53,126.9045,5,16,"#00FF66"], ["Xenon","Xe",54,131.293,5,17,"#00CCFF"], ["Cesium","Cs",55,132.9054,6,0,"#FF9900"], ["Baryum","Ba",56,137.327,6,1,"#FFFF33"], ["Lanthane","La",57,138.9055,6,2,"#FFCCCC"], ["Cerium","Ce",58,140.116,8,4,"#CCCC66"], ["Praseodyme","Pr",59,140.9076,8,5,"#CCCC66"], ["Neodyme","Nd",60,144.24,8,6,"#CCCC66"], ["Promethium","Pm",61,145,8,7,"#CCCC66"], ["Samarium","Sm",62,150.36,8,8,"#CCCC66"], ["Europium","Eu",63,151.964,8,9,"#CCCC66"], ["Gadolinium","Gd",64,157.25,8,10,"#CCCC66"], ["Terbium","Tb",65,158.9253,8,11,"#CCCC66"], ["Dysprosium","Dy",66,162.500,8,12,"#CCCC66"], ["Holmium","Ho",67,164.9303,8,13,"#CCCC66"], ["Erbium","Er",68,167.259,8,14,"#CCCC66"], ["Thulium","Tm",69,168.9342,8,15,"#CCCC66"], ["Ytterbium","Yb",70,173.04,8,16,"#CCCC66"], ["Lutecium","Lu",71,174.967,8,17,"#CCCC66"], ["Hafnium","Hf",72,178.49,6,3,"#FFCCCC"], ["Tantale","Ta",73,180.9479,6,4,"#FFCCCC"], ["Tungstene","W",74,183.84,6,5,"#FFCCCC"], ["Rhenium","Re",75,186.207,6,6,"#FFCCCC"], ["Osmium","Os",76,190.23,6,7,"#FFCCCC"], ["Iridium","Ir",77,192.217,6,8,"#FFCCCC"], ["Platine","Pt",78,195.078,6,9,"#FFCCCC"], ["Or","Au",79,166.9665,6,10,"#FFCCCC"], ["Mercure","Hg",80,200.59,6,11,"#FFCCCC"], ["Thallium","Tl",81,204.3833,6,12,"#9999FF"], ["Plomb","Pb",82,207.2,6,13,"#9999FF"], ["Bismuth","Bi",83,208.9803,6,14,"#9999FF"], ["Polonium","Po",84,209,6,15,"#9999FF"], ["Astate","At",85,210,6,16,"#00FF66"], ["Radon","Rd",86,222,6,17,"#00CCFF"], ["Francium","Fr",87,223,7,0,"#FF9900"], ["Radium","Ra",88,226,7,1,"#FFFF33"], ["Actinium","Ac",89,227,7,2,"#FFCCCC"], ["Thorium","Th",90,232.0381,9,4,"#FF3300"], ["Protactinium","Pa",91,231.0359,9,5,"#FF3300"], ["Uranium","U",92,238.02891,9,6,"#FF3300"], ["Neptunium","Np",93,237,9,7,"#FF3300"], ["Plutonium","Pu",94,244,9,8,"#FF3300"], ["Americium","Am",95,243,9,9,"#FF3300"], ["Curium","Cm",96,247,9,10,"#FF3300"], ["Berkelium","Bk",97,247,9,11,"#FF3300"], ["Californium","Cf",98,251,9,12,"#FF3300"], ["Einsteinium","Es",99,252,9,13,"#FF3300"], ["Fermium","Fm",100,257,9,14,"#FF3300"], ["Mendelevium","Md",101,258,9,15,"#FF3300"], ["Nobelium","No",102,259,9,16,"#FF3300"], ["Lawrencium","Lr",103,262,9,17,"#FF3300"], ["Rutherfordium","Rf",104,261,7,3,"#FFCCCC"], ["Dubnium","Db",105,262,7,4,"#FFCCCC"], ["Seaborgium","Sg",106,266,7,5,"#FFCCCC"], ["Bohrium","Bh",107,264,7,6,"#FFCCCC"], ["Hassium","Hs",108,269,7,7,"#FFCCCC"], ["Meitneium","Mt",109,268,7,8,"#FFCCCC"], ["Darmstadtium","Ds",110,271,7,9,"#FFCCCC"], ["Roentgenium","Rg",111,272,7,10,"#FFCCCC"], ["Copernicium","Cn",112,285,7,11,"#FFCCCC"], ["Ununtrium","Uut",113,184,7,12,"#9999FF"], ["Ununquadium","Uuq",114,289,7,13,"#9999FF"], ["Ununpentium","Uup",115,288,7,14,"#9999FF"], ["Ununhexium","Uuh",116,292,7,15,"#9999FF"], ["Ununseptium","Uus",117,"-",7,16,"white"], ["Ununoctium","Uuo",118,"-",7,17,"white"] ]