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
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from tkinter import *
# on crée la fenêtre principale
fenetre = Tk()
def delete(event,arg1,arg2):
#print(canvas.grid_slaves(row, column))
for canvas in fenetre.grid_slaves():
if int(canvas.grid_info()["row"]) == arg1:
canvas.grid_forget()
for canvas in fenetre.grid_slaves():
if int(canvas.grid_info()["column"]) == arg2:
canvas.grid_forget()
longueurGrille=50
n=1
j = 1
while j < longueurGrille:
i=1
while i < longueurGrille:
canvas = "canvas" + str(i) + str(j)
canvas = Canvas(fenetre, bg="pale goldenrod")
canvas.grid(row=j, column=i, sticky=NW+SE)
if i == 5:
label = Label(canvas, bg="white", text=n, width=4, height=1, borderwidth=2, relief="solid")
label.bind("<Button-1>", lambda event, arg1=j, arg2=i: delete(event, arg1, arg2))
else:
label = Label(canvas, bg="white", text=n, width=4, height=1, borderwidth=2, relief="solid")
label.bind("<Button-1>", lambda event, arg1=j, arg2=i: delete(event, arg1, arg2))
label.grid(row=j, column=i, sticky=NW+SE)
i=i+1
n=n+1
j=j+1
# on lance la boucle principale
fenetre.mainloop() |
Partager