Python可视化界⾯编程⼊门
Python可视化界⾯编程⼊门具体实现代码如所⽰:
(1)普通可视化界⾯编程代码⼊门:
import sys
from PyQt5.QtWidgets import QWidget,QApplication #导⼊两个类来进⾏程序界⾯编程
if __name__=="__main__":
#创建⼀个Application的类
app=QApplication(sys.argv)
#创建⼀个窗⼝
w=QWidget()
#设置窗⼝的尺⼨⼤⼩
# 移动窗⼝
#设置窗⼝的标题
w.setWindowTitle("得⼀个基于PyQt5的桌⾯应⽤")
#显⽰窗⼝
w.show()
#静进⼊程序的主循环,并且通过exit函数确保主循环的安全结束
<_()) #⼀⼀直在桌⾯上显⽰窗⼝形状
#QTdesigner和pyGUI扩展⼯具在pycharm平台中的的安装和配置
#直接安装QT软件或者安装anaconda开发环境之后就会在电脑安装好⽂件,之后pycharm⾥⾯配置扩展⼯具external tool⽂件,便可以⽅便在pycharm⾥⾯直接启动
在pycharm⾥⾯配置扩展⼯具external toolQTdesigne和pyGUI(可以将ui⽂件直转换为.py⽂件,建⽴设计的可视化界⾯的⼤类直接进⾏
配置好之后设计可视化界⾯的步骤是:
(1)利⽤pychar⾥⾯的QTdesigner扩展⼯具进⾏可视化界⾯的设计,然后将其保存为.ui⽂件;
(2)使⽤pyGUI扩展⼯具将设计好的可视化界⾯.ui⽂件转换为.py⽂件,⽣成⼀个建⽴的可视化模板⼤类,直接进⾏调⽤即可。
具体代码如下所⽰:
import sys
import mainwinvertical #导⼊相应的设计好的QTdesigner主窗⼝的类,然后即可直接进⾏展⽰(由ui⽂件经过PYGUI扩展⼯具转换⽽来)from PyQt5.QtWidgets import QApplication,QMainWindow
if __name__=="__main__":
app=QApplication(sys.argv)
mainwin=QMainWindow() #创建⼀个窗⼝
ui=mainwinvertical.Ui_MainWindow() #创建⼀个QTdesigner的类
ui.setupUi(mainwin) #将对象直接进⾏运⾏设置函数,向主窗⼝上添加控件
mainwin.show() #展⽰出来窗⼝的形式
<_()) #承接开头语句,⽤来实时的显⽰窗⼝
其中mainwinvertical类的具体代码如下:(由QTdesigner设计好可是换界⾯,然后直接⽤pyGUi扩展⼯具转换为.python代码⽂件)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwinvertical.ui'
#
# Created by: PyQt5 UI code generator 5.13.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
self.verticalLayoutWidget = QtWidgets.alwidget)a bite of python下载
self.verticalLayoutWidget.setGeometry(QtCore.QRect(390, 50, 201, 141))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.pushButton_5 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_5.setObjectName("pushButton_5")
self.verticalLayout_2.addWidget(self.pushButton_5)
self.pushButton_4 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_4.setObjectName("pushButton_4")
self.verticalLayout_2.addWidget(self.pushButton_4)
self.pushButton_6 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_6.setObjectName("pushButton_6")
self.verticalLayout_2.addWidget(self.pushButton_6)
self.widget = QtWidgets.alwidget)
self.widget.setGeometry(QtCore.QRect(30, 40, 291, 211))
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.widget)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.pushButton = QtWidgets.QPushButton(self.widget)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.widget)
self.pushButton_2.setObjectName("pushButton_2")
self.verticalLayout.addWidget(self.pushButton_2)
self.lineEdit = QtWidgets.QLineEdit(self.widget)
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout.addWidget(self.lineEdit)
self.pushButton_3 = QtWidgets.QPushButton(self.widget)
self.pushButton_3.setObjectName("pushButton_3")
数据库系统是由什么部分组成self.verticalLayout.addWidget(self.pushButton_3)
MainWindow.alwidget)
MainWindow.ubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
汇编语言四则运算程序self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
tSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = anslate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton_5.setText(_translate("MainWindow", "PushButton")) self.pushButton_4.setText(_translate("MainWindow", "PushButton")) self.pushButton_6.setText(_
translate("MainWindow", "PushButton")) self.label.setText(_translate("MainWindow", "TextLabel"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.pushButton_2.setText(_translate("MainWindow", "PushButton")) self.pushButton_3.setText(_translate("MainWindow", "PushButton"))
具体的运⾏结果如下所⽰:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论