您的位置:首页 > 编程语言 > Qt开发

PyQt5的学习之路(一)

2017-01-14 12:17 197 查看

Ubuntu下PyQt5的安装与测试

安装

在Ubuntu下直接使用命令”sudo apt-get install python-PyQt5”即可安装PyQt5了

测试

测试一代码

test1.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QApplication, QWidget

if __name__ == '__main__':

app = QApplication(sys.argv)   #创建QApplication对象

w = QWidget()     #创建QWidget对象
w.resize( 250, 150 )        #创建窗体大小
w.move( 100, 300 )       #设置在屏幕上的显示位置
w.setWindowTitle( 'hello world agian' )      #设置窗口标题
w.show()           #窗口显示

sys.exit(app.exec_())


测试二代码

test2.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QApplication, QWidget

#自定义类
class myform(QWidget):
def __init__(self):
#QWidget.__init__(self)
super(myform, self).__init__()
#调用父类QWidget的构造函数,这句很重要
self.setWindowTitle('hello world agian')
self.resize(400, 300)

if __name__ == "__main__":
app = QApplication(sys.argv)
w = myform()
w.show()
sys.exit(app.exec_())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ubuntu pyqt