欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用pyuic5將ui文件轉(zhuǎn)換為py文件的方法

 更新時(shí)間:2019年06月19日 09:15:09   作者:yanwucao  
今天小編就為大家分享一篇利用pyuic5將ui文件轉(zhuǎn)換為py文件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

操作系統(tǒng)上正確配置python環(huán)境之后,pyuic5也是一個(gè)可以識(shí)別的命令行指令

到.ui文件的目錄下,直接cmd進(jìn)入,輸入pyuic5 -o 轉(zhuǎn)換的py文件 待轉(zhuǎn)換的ui文件

此時(shí),需要對(duì)login.py添加一點(diǎn)代碼使得設(shè)計(jì)好的UI能夠出現(xiàn)在我們面前

import sys
 
 
if __name__ == "__main__":
  app = QtWidgets.QApplication(sys.argv) # 創(chuàng)建一個(gè)QApplication,也就是你要開(kāi)發(fā)的軟件app
  MainWindow = QtWidgets.QMainWindow()  # 創(chuàng)建一個(gè)QMainWindow,用來(lái)裝載你需要的各種組件、控件
  ui = Ui_Form()             # ui是你創(chuàng)建的ui類(lèi)的實(shí)例化對(duì)象
  ui.setupUi(MainWindow)         # 執(zhí)行類(lèi)中的setupUi方法,方法的參數(shù)是第二步中創(chuàng)建的QMainWindow
  MainWindow.show()            # 執(zhí)行QMainWindow的show()方法,顯示這個(gè)QMainWindow
  sys.exit(app.exec_())          # 使用exit()或者點(diǎn)擊關(guān)閉按鈕退出QApplication

完整代碼段如下:

# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
 
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
 
 
class Ui_Form(object):
  def setupUi(self, Form):
    Form.setObjectName("Form")
    Form.resize(400, 300)
    self.pushButton = QtWidgets.QPushButton(Form)
    self.pushButton.setGeometry(QtCore.QRect(70, 220, 75, 23))
    self.pushButton.setObjectName("pushButton")
    self.pushButton_2 = QtWidgets.QPushButton(Form)
    self.pushButton_2.setGeometry(QtCore.QRect(220, 220, 75, 23))
    self.pushButton_2.setObjectName("pushButton_2")
    self.checkBox = QtWidgets.QCheckBox(Form)
    self.checkBox.setGeometry(QtCore.QRect(70, 180, 141, 16))
    self.checkBox.setObjectName("checkBox")
    self.lineEdit = QtWidgets.QLineEdit(Form)
    self.lineEdit.setGeometry(QtCore.QRect(130, 56, 181, 20))
    self.lineEdit.setObjectName("lineEdit")
    self.lineEdit_2 = QtWidgets.QLineEdit(Form)
    self.lineEdit_2.setGeometry(QtCore.QRect(130, 110, 181, 20))
    self.lineEdit_2.setObjectName("lineEdit_2")
    self.label = QtWidgets.QLabel(Form)
    self.label.setGeometry(QtCore.QRect(70, 60, 54, 12))
    self.label.setObjectName("label")
    self.label_2 = QtWidgets.QLabel(Form)
    self.label_2.setGeometry(QtCore.QRect(70, 110, 54, 12))
    self.label_2.setObjectName("label_2")
 
    self.retranslateUi(Form)
    QtCore.QMetaObject.connectSlotsByName(Form)
 
  def retranslateUi(self, Form):
    _translate = QtCore.QCoreApplication.translate
    Form.setWindowTitle(_translate("Form", "Form"))
    self.pushButton.setText(_translate("Form", "取消"))
    self.pushButton_2.setText(_translate("Form", "確定"))
    self.checkBox.setText(_translate("Form", "記住用戶(hù)名和密碼"))
    self.label.setText(_translate("Form", "用戶(hù)名:"))
    self.label_2.setText(_translate("Form", "密碼:"))
 
 
if __name__ == "__main__":
  app = QtWidgets.QApplication(sys.argv) # 創(chuàng)建一個(gè)QApplication,也就是你要開(kāi)發(fā)的軟件app
  MainWindow = QtWidgets.QMainWindow()  # 創(chuàng)建一個(gè)QMainWindow,用來(lái)裝載你需要的各種組件、控件
  ui = Ui_Form()             # ui是你創(chuàng)建的ui類(lèi)的實(shí)例化對(duì)象
  ui.setupUi(MainWindow)         # 執(zhí)行類(lèi)中的setupUi方法,方法的參數(shù)是第二步中創(chuàng)建的QMainWindow
  MainWindow.show()            # 執(zhí)行QMainWindow的show()方法,顯示這個(gè)QMainWindow
  sys.exit(app.exec_())          # 使用exit()或者點(diǎn)擊關(guān)閉按鈕退出QApplication
 

結(jié)果顯示如下:

以上這篇利用pyuic5將ui文件轉(zhuǎn)換為py文件的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論