zoukankan      html  css  js  c++  java
  • python在Qt下的界面编程

    准备工作

    • python3.5以上,目前安装为anaconda
    • Qt5.9,安装过程见以前文章
    • PyQt5.6,通过anaconda更新
    • 示例程序:CRC校验

    创建界面

    • 通过qt designer设计界面,一个输入text edit,一个输出text edit,一个按键pushbutton,保存".ui"文件到python工程目录

    • 创建一个python界面的启动脚本mainwin.py,加入以下内容:

    import sys
    from PyQt5 import QtCore, QtGui, uic,QtWidgets
     
    qtCreatorFile = "MainWindow.ui" # Enter file here.
     
    Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
    
    class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self):
            QtWidgets.QMainWindow.__init__(self)
            Ui_MainWindow.__init__(self)
            self.setupUi(self)
            self.pushButton.clicked.connect(self.CalculateCKV)
        def CalculateCKV(self):
            stringin = str(self.textEdit_2.toPlainText())
            self.textEdit.setText(stringin)
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        window = MyApp()
        window.show()
        sys.exit(app.exec_())
    

    注意qtCreatorFile = "MainWindow.ui" # Enter file here.这里要换成相应的.ui文件。

    程序流程

    window = MyApp()这里进入__init__(self),初始化后创建了一个沟槽self.pushButton.clicked.connect(self.CalculateCKV),即pushButton按下后会调用MyApp下面的CalculateCKV函数,CalculateCKV传进来的参数是MyApp里面所包含的,即self包括了pushbutton和textEdit等,直接复制文本显示到另一个文本框中

  • 相关阅读:
    用Python获取Linux资源信息的三种方法
    对python中元类的理解
    一道有趣的和编程无关的编程题思考
    Python编程进阶
    函数计算的 Python手册小问题
    Linux 命令
    pyechart
    KV数据库Redis
    微博API 学习记录
    非阻塞式的 requests.post 学习
  • 原文地址:https://www.cnblogs.com/RegressionWorldLine/p/8379833.html
Copyright © 2011-2022 走看看