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
| import tkinter as tk
from tkinter import *
myLenght=20
DIM_GRILLE = (myLenght, myLenght)
DIM_CASEL = 30
DIM_CASEH = 15
DIM_LIGNE = 1
DIM_CANEVAS = (
DIM_GRILLE[0]*DIM_CASEL + (DIM_GRILLE[0]+1)*DIM_LIGNE,
DIM_GRILLE[1]*DIM_CASEH + (DIM_GRILLE[1]+1)*DIM_LIGNE
)
fenetre = tk.Tk()
can = tk.Canvas(
fenetre,
width=DIM_CANEVAS[0],
height=DIM_CANEVAS[1],
bg='black',
highlightthickness=0,
)
can.grid()
can2 = tk.Canvas(
fenetre,
width=DIM_CANEVAS[0],
height=DIM_CANEVAS[1],
bg='black',
highlightthickness=0,
)
can2.grid()
colors = ['white', 'yellow']
y = DIM_LIGNE
DIM_CASE =10
for ligne in range(DIM_GRILLE[1]) :
x = DIM_LIGNE
colors.reverse()
for col in range(DIM_GRILLE[0]) :
i = can.create_rectangle(
x, y, x+DIM_CASEL, y+DIM_CASEH,
fill=colors[col%2],
width=0,
tags='l{} c{}'.format(ligne, col),
)
x += DIM_CASEL + DIM_LIGNE
y += DIM_CASEH + DIM_LIGNE
button1 = Button(can2, text='Générateur')
button1.grid(row=0, column=0, rowspan=1, sticky='ew')
fenetre.mainloop() |
Partager