zoukankan      html  css  js  c++  java
  • pyqt 调用QT设计师创建的对话框

    一、实验环境

    1.Windows7x64_SP1

    2.anaconda2.5.0 + python2.7(anaconda集成,不需单独安装)

    3.pyinstaller3.0

    二、实验步骤

    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设计排版存在差异,不推荐使用!

    2.5 槽函数调用对话框方式

    请参考:https://www.cnblogs.com/hester/p/11229751.html

  • 相关阅读:
    构建之法读书笔记 第4章 两人合作
    ASE19 团队项目 alpha 阶段 Frontend 组 scrum9 记录
    ASE —— 第二次结对作业
    ASE —— 第一次结对作业
    高级软件工程 —— 第一周博客作业
    软工个人总结
    六月上团队项目心得
    团队项目心得
    结对编程收获
    结对作业——随机生成四则运算(Core 第7组)
  • 原文地址:https://www.cnblogs.com/hester/p/11230157.html
Copyright © 2011-2022 走看看