4 Star 21 Fork 9

木子/PyQt_practice

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
03-QWidget-案例.py 840 Bytes
一键复制 编辑 原始数据 按行查看 历史
木子 提交于 2022-02-21 20:53 +08:00 . Reformat code with isort
import sys
from PyQt5.Qt import *
"""案例要求:将20个大小相同的子控件以3列均匀填满窗口"""
app = QApplication(sys.argv)
window = QWidget()
window.show()
window.resize(500, 500)
# 总的控件个数
widget_count = 20
# 一行有多少列
column_count = 3
# 计算一个控件的宽度
widget_width = int(window.width() / column_count)
# 总共多少行 (编号 // 列数 + 1)
row_count = (widget_count - 1) // column_count + 1
widget_height = int(window.height() / row_count)
for i in range(0, widget_count):
w = QWidget(window)
w.resize(widget_width, widget_height)
widget_x = i % column_count * widget_width
widget_y = i // column_count * widget_height
w.move(widget_x, widget_y)
w.setStyleSheet("background-color: green; border: 3px solid cyan;")
w.show()
sys.exit(app.exec_())
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/muzing/PyQt_practice.git
git@gitee.com:muzing/PyQt_practice.git
muzing
PyQt_practice
PyQt_practice
master

搜索帮助