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 77 78 79 80 81 82 83 84 85
| 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]+1)*DIM_LIGNE,
DIM_GRILLE[1]*DIM_CASE[0] + (DIM_GRILLE[1]+1)*DIM_LIGNE
)
def delete(evt) :
NBRELignes[0] = NBRELignes[0]-1
print(DIM_CASE[0])
DIM_CASE[0]=int(DIM_CANEVAS[0]/NBRELignes[0])
r = can.find_overlapping(evt.x, evt.y, evt.x, evt.y)
print(DIM_CASE[0])
#print(NBRELignes[0])
if not r :
return
ligne, colonne = can.gettags(r[0])[:2]
iligne, icolonne = int(ligne[1:]), int(colonne[1:])
#print(iligne)
#print(icolonne)
for i in range(iligne+1, DIM_GRILLE[1]+1) :
can.move('l'+str(i), 0, -(DIM_CASE[0]+DIM_LIGNE))
for i in range(icolonne+1, DIM_GRILLE[0]+1) :
can.move('c'+str(i), -(DIM_CASE[0]+DIM_LIGNE), 0)
can.delete(ligne)
can.delete(colonne)
#myGrid()
can.forget()
fenetre = tk.Tk()
can = tk.Canvas(fenetre, width=DIM_CANEVAS[0], height=DIM_CANEVAS[1], bg='black', highlightthickness=0,
)
can.grid()
def myGrid():
items = []
colors = ['red', 'yellow']
colors2 = 'green'
y = DIM_LIGNE
#print(DIM_GRILLE[0])
for ligne in range(DIM_GRILLE[1]) :
x = DIM_LIGNE
ids = []
colors.reverse()
for col in range(DIM_GRILLE[0]) :
#print(DIM_CASE[0])
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