pyqt 調用QT設計師建立的對話框

1、實驗環境

1.Windows7x64_SP1

2.anaconda2.5.0 + python2.7(anaconda集成,不需單獨安裝)

3.pyinstaller3.0

2、實驗步驟

2.1 QT設計師建立主對話框以下

2.3 主程序中調用方式一

2.3.1 使用pyuic5生成untitled.py

pyuic5 -o untitled.py untitled.ui

2.3.2 主程序調用代碼

# -*- coding: utf-8 -*-
import os,sys,time,re
import xlrd
from PyQt5.QtWidgets import QMainWindow,QMessageBox
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QDialog
from PyQt5 import QtCore,QtGui
from untitled import Ui_MainWindow


class SmartBit_Tool(QMainWindow):
    host_ip = '192.168.8.85'
    username = 'su'
    password = 'SMB-6000'
    excel_file = 'IP_Name.xlsx'
    smart_ip_list_file = 'smart_ip_list.txt'
    srcFilename = os.path.join('\\\\192.168.8.123\\software', excel_file)
    desFilename = os.path.join(os.getcwd(),excel_file)
    smart_ip_list_file = os.path.join(os.getcwd(),smart_ip_list_file)

    def __init__(self, *args):
        super(SmartBit_Tool, self).__init__(*args)
        self.ret_ping_test = False
        self.ui = Ui_MainWindow()                                                  #實例化窗口
        self.ui.setupUi(self)                                                      #顯示窗口

2.4 主程序中調用方式二

# -*- coding: utf-8 -*-
import os,sys,time,re
import xlrd
from PyQt5.QtWidgets import QMainWindow,QMessageBox
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QDialog
from PyQt5 import QtCore,QtGui


class SmartBit_Tool(QMainWindow):
    def __init__(self, *args):
        super(SmartBit_Tool, self).__init__(*args)
        loadUi('untitled.ui', self)
        self.setWindowTitle('SmartBit_Get_User')  

如上方式使用loadUI函數直接調用*.ui,未進行pyuic5生成untitled.py,對話框顯示跟QT設計排版存在差別,不推薦使用!html

2.5 槽函數調用對話框方式

請參考:http://www.javashuo.com/article/p-zekmgjka-gu.htmlpython

相關文章
相關標籤/搜索