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 86 87 88 89 90 91 92 93 94 95 96 97 98
| from tkinter import *
root = Tk()
can = Canvas(root, width=2000, height=2000, background='ivory')
can.pack()
echecs = Frame(can, borderwidth=10, padx=100, pady=50)
echecs.pack(side=LEFT)
Colonnes = [-1,1,2,3,4,5,6,7,8,-1]
Lignes = [-1,1,2,3,4,5,6,7,8,-1]
tour_blanc = PhotoImage(file='tour.blanc.png')
tour_noir = PhotoImage(file='tour.noir.png')
cavalier_blanc = PhotoImage(file='cavalier.blanc.png')
cavalier_noir = PhotoImage(file='cavalier.noir.png')
fou_blanc = PhotoImage(file='fou.blanc.png')
fou_noir = PhotoImage(file='fou.noir.png')
roi_blanc = PhotoImage(file='roi.blanc.png')
roi_noir = PhotoImage(file='roi.noir.png')
reine_blanc = PhotoImage(file='reine.blanc.png')
reine_noir = PhotoImage(file='reine.noir.png')
pion_blanc = PhotoImage(file='pion.blanc.png')
pion_noir = PhotoImage(file='pion.noir.png')
color_red = ['red', 'blue']
color2=['black','white']
color1=['white','black']
j=1
i=1
c=1
cases=[]
def tbs(tb) :
tb.grid(column=1, row=5, sticky='nesw')
while j < 9 :
while i < 9 :
if (j == 1 or j == 8) and (i == 1 or i == 8):
if i == 1 :
tb = Button(echecs, image=tour_blanc, text= str(i)+str(j), bg='black', fg='white', relief=FLAT)
a1=Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN, command=tbs(tb))
a1.grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=tour_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
elif (j == 2 or j == 7) and (i == 1 or i == 8):
if i == 1 :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=cavalier_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=cavalier_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
elif (j == 3 or j == 6) and (i == 1 or i == 8):
if i == 1 :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=fou_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=fou_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
elif j == 4 and (i == 1 or i == 8):
if i == 1 :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=roi_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=roi_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
elif j == 5 and (i == 1 or i == 8):
if i == 1 :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=reine_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=reine_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
elif i == 2 or i == 7 :
if i == 2 :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=pion_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
Button(echecs, image=pion_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
else :
Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
c=1-c
i+=1
i=1
j+=1
c=1-c
print(echecs.grid_slaves(column=1, row= 5))
#tb.grid_remove()
#tb.grid()
root.mainloop() |
Partager