>>> pyqt5 + QT designer专栏<<<
视频地址:
https://www.bilibili.com/video/BV154411n79k?p=24
这期弹幕很搞笑,老师翻车了。。。写了函数,居然不调用。
不过我已经在代码里补充完整了
课程重点:
就是让窗口居中显示,没啥好说的
完整代码:
# QDesktopWidget
import sys
from PyQt5.QtWidgets import QDesktopWidget,QMainWindow,QApplication
from PyQt5.QtGui import QIcon
class CenterForm(QMainWindow):
def __init__(self):
super(CenterForm,self).__init__()
# 设置主窗口的标题
self.setWindowTitle('让窗口居中')
# 设置窗口的尺寸
self.resize(400,300)
def center(self): # 定义一个函数使得窗口居中显示
# 获取屏幕坐标系
screen = QDesktopWidget().screenGeometry()
# 获取窗口坐标系
size = self.geometry()
newLeft = (screen.width() - size.width()) / 2
newTop = (screen.height() - size.height()) / 2
self.move(int(newLeft),int(newTop))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = CenterForm()
main.center() #课程的代码里少了这个调用,加上以后效果好多了
main.show()
sys.exit(app.exec_())