from tkinter import* from random import* coteducarre=20 mafenetre = Tk() couleurcourante=5 monbouton=() marge=10 Liste_des_couleurs=['red', 'yellow', 'green', 'blue', 'orange', 'purple', 'pink', 'white'] mafenetre.geometry("500x400") moncanvas = Canvas(mafenetre, width=110, height=300, background='white') rectangle1 = moncanvas.create_rectangle(marge, 0, 110, 300) for j in range(0,16): ligne1 = moncanvas.create_line(marge, 20*j, 110, 20*j) for i in range(0,5): colonne = moncanvas.create_line(10+20*i, 0, 10+20*i,300) chaine=Label(mafenetre) chaine.grid() def action_en_cas_de_pointeur(evenement): if evenement.x<30 and evenement.x>10: chaine['text']="Colonne 1" if evenement.x<50 and evenement.x>30: chaine['text']="Colonne 2" if evenement.x<70 and evenement.x>50: chaine['text']="Colonne 3" if evenement.x<90 and evenement.x>70: chaine['text']="Colonne 4" if evenement.x<110 and evenement.x>90: chaine['text']="Colonne 5" def fonction_commandee_par_le_bouton(numerobouton): global couleurcourante,monlabel if numerobouton==1: monlabel['text']="Couleur : Rouge" couleurcourante=0 if numerobouton==2: monlabel['text']="Couleur : Jaune" couleurcourante=1 if numerobouton==3: monlabel['text']="Couleur : Vert" couleurcourante=2 if numerobouton==4: monlabel['text']="Couleur : Bleu" couleurcourante=3 if numerobouton==5: monlabel['text']="Couleur : Orange" couleurcourante=4 if numerobouton==6: monlabel['text']="Couleur : Violet" couleurcourante=5 if numerobouton==7: monlabel['text']="Couleur : Rose" couleurcourante=6 if numerobouton==8: monlabel['text']="Couleur : Vide" couleurcourante=7 monbouton = Button(mafenetre, text="Rouge", command=lambda numero=1:fonction_commandee_par_le_bouton(numero)).grid(row=1, column=1) monbouton1 = Button(mafenetre, text="Jaune", command=lambda numero=2:fonction_commandee_par_le_bouton(numero)).grid(row=2, column=1) monbouton2 = Button(mafenetre, text="Vert", command=lambda numero=3:fonction_commandee_par_le_bouton(numero)).grid(row=3, column=1) monbouton3 = Button(mafenetre, text="Bleu", command=lambda numero=4:fonction_commandee_par_le_bouton(numero)).grid(row=4, column=1) monbouton4 = Button(mafenetre, text="Orange", command=lambda numero=5:fonction_commandee_par_le_bouton(numero)).grid(row=5, column=1) monbouton5 = Button(mafenetre, text="Violet", command=lambda numero=6:fonction_commandee_par_le_bouton(numero)).grid(row=6, column=1) monbouton6 = Button(mafenetre, text="Rose", command=lambda numero=7:fonction_commandee_par_le_bouton(numero)).grid(row=7, column=1) monbouton7 = Button(mafenetre, text="Vide", command=lambda numero=8:fonction_commandee_par_le_bouton(numero)).grid(row=8, column=1) monbouton10 = Button(mafenetre, text="Verifier", command=fonction_commandee_par_le_bouton).grid(row=10, column=1) monlabel=Label(mafenetre, text="Couleur:", fg='black') monlabel.grid(row=9, column=1) #monlabel=Label(mafenetre, text="Couleur : Violet", fg='Violet').grid(row=9, column=1) combinaisonatrouver=[0,0,0,0,0] for i in range(0,5): variable = randint(1,8) combinaisonatrouver[i]=variable print(combinaisonatrouver) combinaisonjoueur=[7,7,7,7,7] def comparaisondeslistes(): for i in range(0,5): if combinaisonatrouver[i]==combinaisonjoueur[i]: combinaisonatrouver[i]==combinaisonjoueur[a] #mafenetre.bind("", comparaisondeslistes) def action_en_cas_de_clic(evenement): if evenement.x>10 and evenement.x<30 and evenement.y>280: moncanvas.create_rectangle(10,300, 30, 280, fill=Liste_des_couleurs[couleurcourante]) mafenetre.bind("", action_en_cas_de_clic) moncanvas.bind("", action_en_cas_de_pointeur) moncanvas.grid(row=1, rowspan=17, column=0) mafenetre.mainloop()