import sys
from PySide2.QtWidgets import *
def __init__(self):
super(SudokuGrid, self).__init__()
self.initGUI()
def initGUI(self):
self.setWindowTitle("Sudoku Grid Example")
self.setGeometry(800, 800, 400, 350)
self.setGrid()
def setGrid(self):
hline.
setFrameShape(QFrame.
HLine) hline.
setFrameShadow(QFrame.
Sunken)
vline.
setFrameShape(QFrame.
VLine) vline.
setFrameShadow(QFrame.
Sunken)
gridLayout.addLayout(box1,0,0)
gridLayout.addWidget(vline, 0, 1)
gridLayout.addLayout(box2,0,2)
gridLayout.addWidget(vline, 0, 3)
gridLayout.addLayout(box3,0,4)
gridLayout.addWidget(hline, 1, 0, 1, 3)
gridLayout.addLayout(box4,2,0)
gridLayout.addWidget(vline, 2, 1)
gridLayout.addLayout(box5,2,2)
gridLayout.addWidget(vline, 2, 3)
gridLayout.addLayout(box6,2,4)
gridLayout.addWidget(hline, 3, 0, 1, 3)
gridLayout.addLayout(box7,4,0)
gridLayout.addWidget(vline, 4, 1)
gridLayout.addLayout(box8,4,2)
gridLayout.addWidget(vline, 4, 3)
gridLayout.addLayout(box9,4,4)
pos = [(0,0),(0,1),(0,2),
(1,0),(1,1),(1,2),
(2,0),(2,1),(2,2)]
i = 0
while i < 9:
box1.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box2.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box3.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box4.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box5.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box6.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box7.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box8.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) box9.
addWidget(QLabel("1"), pos
[i
][0], pos
[i
][1]) i = i + 1
self.setLayout(gridLayout)
if __name__ == '__main__':
try:
myWindow = SudokuGrid()
myWindow.show()
myApp.exec_()
sys.exit(0)
except NameError:
print("Name Error:", sys.exc_info()[1])
except SystemExit:
print("Closing Window...")
except Exception:
print(sys.exc_info()[1])
import sys
from PySide2.QtWidgets import *
class SudokuGrid(QWidget):
def __init__(self):
super(SudokuGrid, self).__init__()
self.initGUI()
def initGUI(self):
self.setWindowTitle("Sudoku Grid Example")
self.setGeometry(800, 800, 400, 350)
self.setGrid()
def setGrid(self):
gridLayout = QGridLayout()
box1 = QGridLayout()
box2 = QGridLayout()
box3 = QGridLayout()
box4 = QGridLayout()
box5 = QGridLayout()
box6 = QGridLayout()
box7 = QGridLayout()
box8 = QGridLayout()
box9 = QGridLayout()
hline = QFrame()
hline.setFrameShape(QFrame.HLine)
hline.setFrameShadow(QFrame.Sunken)
vline = QFrame()
vline.setFrameShape(QFrame.VLine)
vline.setFrameShadow(QFrame.Sunken)
gridLayout.addLayout(box1,0,0)
gridLayout.addWidget(vline, 0, 1)
gridLayout.addLayout(box2,0,2)
gridLayout.addWidget(vline, 0, 3)
gridLayout.addLayout(box3,0,4)
gridLayout.addWidget(hline, 1, 0, 1, 3)
gridLayout.addLayout(box4,2,0)
gridLayout.addWidget(vline, 2, 1)
gridLayout.addLayout(box5,2,2)
gridLayout.addWidget(vline, 2, 3)
gridLayout.addLayout(box6,2,4)
gridLayout.addWidget(hline, 3, 0, 1, 3)
gridLayout.addLayout(box7,4,0)
gridLayout.addWidget(vline, 4, 1)
gridLayout.addLayout(box8,4,2)
gridLayout.addWidget(vline, 4, 3)
gridLayout.addLayout(box9,4,4)
pos = [(0,0),(0,1),(0,2),
(1,0),(1,1),(1,2),
(2,0),(2,1),(2,2)]
i = 0
while i < 9:
box1.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box2.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box3.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box4.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box5.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box6.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box7.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box8.addWidget(QLabel("1"), pos[i][0], pos[i][1])
box9.addWidget(QLabel("1"), pos[i][0], pos[i][1])
i = i + 1
self.setLayout(gridLayout)
if __name__ == '__main__':
try:
myApp = QApplication(sys.argv)
myWindow = SudokuGrid()
myWindow.show()
myApp.exec_()
sys.exit(0)
except NameError:
print("Name Error:", sys.exc_info()[1])
except SystemExit:
print("Closing Window...")
except Exception:
print(sys.exc_info()[1])
To copy to clipboard, switch view to plain text mode
Bookmarks