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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| import tkinter as tk
DIM_GRILLE = (10, 10)
#DIM_CASE = 15
DIM_LIGNE = 1
DIM_CASE =[60]
NBRELignes=[10]
DIM_CANEVAS = (
DIM_GRILLE[0]*DIM_CASE[0] + (DIM_GRILLE[0])*DIM_LIGNE,
DIM_GRILLE[1]*DIM_CASE[0] + (DIM_GRILLE[1])*DIM_LIGNE
)
def delete(evt) :
NBRELignes[0] = NBRELignes[0]-1
#print(DIM_CANEVAS[0])
#DIM_CASE[0]=DIM_CANEVAS[0]//NBRELignes[0]
print(DIM_CASE[0])
#print(NBRELignes[0])
r = can.find_overlapping(evt.x, evt.y, evt.x, evt.y)
if not r :
return
ligne, colonne = can.gettags(r[0])[:2]
iligne, icolonne = int(ligne[1:]), int(colonne[1:])
j=evt.x//60
i=evt.y//60
print(items[0][0])
can.coords(items[0][0],1,1,50,50)
can.coords(items[2][0],1,1,50,50)
fenetre = tk.Tk()
can = tk.Canvas(fenetre, width=DIM_CANEVAS[0], height=DIM_CANEVAS[1], bg='black', highlightthickness=0,
)
can.grid()
items = []
colors = ['red', 'yellow']
colors2 = 'green'
#print(DIM_GRILLE[0])
def myGrid(arg=DIM_CASE[0]):
y = DIM_LIGNE
for ligne in range(DIM_GRILLE[1]) :
x = DIM_LIGNE
ids = []
colors.reverse()
for col in range(DIM_GRILLE[0]) :
#print(DIM_CASE[0])
#print(str(col)+str(ligne))
i = can.create_rectangle(
x, y, x+DIM_CASE[0], y+DIM_CASE[0],
#fill=colors[col%2],
fill=colors2,
width=0,
tags='l{} c{}'.format(ligne, col),
)
ids.append(i)
x += DIM_CASE[0] + DIM_LIGNE
items.append(ids)
y += DIM_CASE[0] + DIM_LIGNE
can.bind('<Button-1>', delete)
myGrid()
fenetre.mainloop() |
Partager