Advertisement
Kaadem-85

Damier

Nov 16th, 2016
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf8 -*-
  3.  
  4. from tkinter import *
  5.  
  6. class Damier(object):
  7.     "Création du damier et des pions"
  8.    
  9.     def __init__(self) :
  10.         "Méthode constructeur"
  11.         self.x = 90
  12.    
  13.     def damier(self):
  14.         "Création du damier"
  15.         self.main_window = Tk()
  16.         self.main_window.title("Jeu de dames")
  17.         self.main_window.resizable(False, False)
  18.  
  19.         self.cadre_principal = Frame(self.main_window, bg = 'black')
  20.         self.cadre_principal.grid()
  21.  
  22.         self.can = Canvas(self.cadre_principal, width = self.x * 10, height = self.x * 10, bg = "white")
  23.         self.can.grid(row = 0, column = 0, columnspan = 2)
  24.         for i in range(0, 10, 2) :
  25.             for i2 in range(0, 10, 2):
  26.                 self.can.create_rectangle(self.x * i2, self.x * i, self.x * (i2 + 1), self.x * (i + 1), width = 2, fill = "black")
  27.                 self.can.create_rectangle(self.x * (i2 + 1), self.x * (i + 1), self.x * (i2 + 2), self.x * (i + 2), width = 2, fill = "black")
  28.  
  29.         self.creer_pions = Button(self.cadre_principal, text = "Activer les pions", bg = 'white', fg = 'black', font = ('Times', '14', 'bold'), relief = 'ridge', bd = 3, command = self.pions)
  30.         self.creer_pions.grid(row = 1, column = 0, padx = 10, pady = 10, sticky = 'e')
  31.  
  32.         self.quitter = Button(self.cadre_principal, text = "Quitter", bg = 'white', fg = 'black', font = ('Times', '14', 'bold'), relief = 'ridge', bd = 3, command = self.main_window.destroy)
  33.         self.quitter.grid(row = 1, column = 1, padx = 10, pady = 10, sticky = 'w')
  34.  
  35.         self.main_window.mainloop()
  36.                
  37.     def pions(self):
  38.         "Création des pions"
  39.         self.ajuster_pion = 5 if self.x <= 50 else 10
  40.         print(self.ajuster_pion)
  41.         for i in range(0, 10, 2) :
  42.             self.color = 'maroon' if i >= 6 else 'ivory'
  43.             for i2 in range(0, 10, 2):
  44.                 if i <= 2 or i >= 6 :
  45.                     self.can.create_oval((self.x * i2) + self.ajuster_pion, (self.x * i) + self.ajuster_pion, (self.x * (i2 + 1)) - self.ajuster_pion, (self.x * (i + 1)) - self.ajuster_pion, width = 2, fill = self.color)
  46.                     self.can.create_oval((self.x * (i2 + 1)) + self.ajuster_pion, (self.x * (i + 1)) + self.ajuster_pion, (self.x * (i2 + 2)) - self.ajuster_pion, (self.x * (i + 2)) - self.ajuster_pion, width = 2, fill = self.color)
  47.  
  48. #======== Main Program =======================
  49.  
  50. damier = Damier()
  51. damier.damier()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement