赞
踩
from PyQt5.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
w = QWidget()
w.resize(300, 300) # 宽x高
w.move(300, 300) # 坐标
w.setWindowTitle("Simple")
w.show()
class Example(QWidget):
def __init__(self):
# super()调用父类QWidget的方法
super().__init__()
# 把绘制界面的任务交给initUI方法
self.initUI()
def initUI(self):
# 设置窗口的位置和大小
self.setGeometry(300, 300, 300, 300)
# 设置窗口图标,引用当前目录下的web.png图片
self.setWindowIcon(QIcon("web.png"))
# 显示窗口
self.show()
QToolTip.setFont(QFont("SansSerif", 10))
from PyQt5.QtWidgets import QPushButton
btn = QPushButton('Button', self)
btn.setToolTip('This is a <b>QPushButton</b> widget')
# btn.sizeHint()显示默认尺寸
btn.resize(btn.sizeHint())
from PyQt5.QtCore import QCoreApplication
qbtn = QPushButton("Quit", self)
qbtn.cliked.connect(QCoreApplication.instance().quit)
def closeEvent(self, event):
reply = QMessageBox.question(self, 'Message',"Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Py40 PyQt5 tutorial This program centers a window on the screen. author: Jan Bodnar website: py40.com last edited: January 2015 """ import sys from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.resize(250, 150) self.center() self.setWindowTitle('Center') self.show() #控制窗口显示在屏幕中心的方法 def center(self): #获得窗口 qr = self.frameGeometry() #获得屏幕中心点 cp = QDesktopWidget().availableGeometry().center() #显示到屏幕中心 qr.moveCenter(cp) self.move(qr.topLeft()) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。