1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
# Nota : Du code existe ici qui fonctionne (remplissage de tableaux)
# --------------------------------------------------------------------------------
# IMPORTATION DE TKINTER
# --------------------------------------------------------------------------------
from tkinter import *
# --------------------------------------------------------------------------------
# CREATION DE LA CLASSE Interface DERIVEE DE Frame
# --------------------------------------------------------------------------------
class Interface(Frame):
def __init__(self, fenetre, **kwargs):
Frame.__init__(self, fenetre, width=800, height=600, **kwargs)
self.pack(fill=BOTH)
self.nbre_points=0
# -------------------------------------------------------------------------
# CREATION GRAPHIQUE DES WIDGETS BOUTONS
# -------------------------------------------------------------------------
i = 0
j = 0
n = 0
for i in range(4):
for j in range(4):
photo[n] = PhotoImage(file= monjeu[i][j])
mesboutons[i][j] = Button(self, image= photo[n], height = 140, width = 130,command=self.cliquer).grid(row=[i], column=[j])
n = n+1
bouton_new = Button(self,text = "New Game", command = self.quit).grid(row = 4, column = 1)
self.affiche_score = Label(self, text="Votre Score {} points.".format(self.nbre_points)).grid(row = 4, column = 2)
bouton_quit = Button(self,text = "Quit", command = self.quit).grid(row = 4, column = 3)
def cliquer(self):
"""Il y a eu un clic sur le bouton.
On change la valeur du label affiche_score"""
self.nbre_points += 1
self.affiche_score["text"] = "Votre Score {} points.".format(self.nbre_points)
fenetre = Tk()
interface = Interface(fenetre)
interface.mainloop()
interface.destroy() |
Partager