p
y
q
t
5
设
置
网
格
布
局
的
间
距
pyqt5 设置网格布局的间距
pyqt5设置网格布局的间距
import sys
from PyQt5.QtWidgets import (QWidget, QGridLayout, QPushButton, QApplication,QLabel)
class GirdWindow(QWidget):
def __init__(self,parent=None,*args,**kwargs):
super().__init__(parent,*args,**kwargs)
self.grid_layout = QGridLayout()
self.setLayout(self.grid_layout)
for x in range(3):
for y in range(3):
xy = str(x)+str(y)
button = QPushButton(xy)
button.setText(xy)
button.clicked.connect(self.hide_self)
button.setStyleSheet("background-color:blue;")
self.grid_layout.addWidget(button, x, y)
self.grid_layout.setSpacing(0)
self.grid_layout.setVerticalSpacing(0)
self.grid_layout.setHorizontalSpacing(0)
self.setWindowTitle('Basic Grid Layout')
def hide_self(self):
print("dfsdf")
self.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
windowExample = GirdWindow()
windowExample.show()
sys.exit(app.exec_())