连着用PyQt做了两次界面,网上中文资料太少和散,官方资料又是纯英文基于Qt的,对新手不太友好。
记录一下自己用到过的函数等。
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
1、这三个module是最常用的。
2、实现将窗口放在屏幕正中
self.desktop_width = QApplication.desktop().width() #屏幕尺寸
self.desktop_height = QApplication.desktop().height()
self.resize(350, 250)
self.move((self.desktop_width-self.width())/2,(self.desktop_height-self.height())/2) #将窗口放在屏幕中间
3、布局
okButton = QPushButton("OK")
cancelButton = QPushButton("Cancel")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
vbox = QVBoxLayout()
vbox.addStretch(1)
vbox