-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (44 loc) · 1.53 KB
/
main.py
File metadata and controls
57 lines (44 loc) · 1.53 KB
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
# coding: utf-8
import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QLabel
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtGui import QPixmap, QIcon
# creer le widget avec le chessboard à placer dans la fenêtre principale
class Chessboard(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# creer une grille de 8x8
self.grid = QGridLayout()
self.setLayout(self.grid)
# creer les cases
for i in range(8):
for j in range(8):
# creer une case
case = QLabel()
# definir la couleur de la case
if (i + j) % 2 == 0:
case.setStyleSheet("background-color: white")
else:
case.setStyleSheet("background-color: black")
# ajouter la case à la grille
self.grid.addWidget(case, i, j)
# creer la fenêtre principale
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
# afficher la fenêtre principale
self.show()
def initUI(self):
# charger le widget chessboard
self.chessboard = Chessboard()
# ajouter le widget chessboard à la fenêtre principale
self.setCentralWidget(self.chessboard)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())