• PyQt5开发相关


    代码来源:cxinping/PyQt5: 《PyQt5快速开发与实战》配套代码 (github.com)

    PyQt5快速开发与实战》

    (1)使用气泡提示

    1. import sys
    2. from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
    3. from PyQt5.QtGui import QFont
    4. class Winform(QWidget):
    5. def __init__(self):
    6. super(Winform, self).__init__()
    7. self.initUI()
    8. def initUI(self):
    9. QToolTip.setFont(QFont('SansSerif', 10))
    10. self.setToolTip('这是一个汽包提示')
    11. self.setGeometry(200, 300, 400, 400)
    12. self.setWindowTitle('气泡提示demo')
    13. if __name__ == "__main__":
    14. app = QApplication(sys.argv)
    15. win = Winform()
    16. win.show()
    17. sys.exit(app.exec_())

     运行截图

    (2)显示QLabel标签

    1. from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
    2. from PyQt5.QtCore import Qt
    3. from PyQt5.QtGui import QPixmap, QPalette
    4. import sys
    5. class WindowDemo(QWidget):
    6. def __init__(self):
    7. super().__init__()
    8. label1 = QLabel(self)
    9. label2 = QLabel(self)
    10. label3 = QLabel(self)
    11. label4 = QLabel(self)
    12. # 初始化标签控件
    13. label1.setText("这是一个文本标签")
    14. label1.setAutoFillBackground(True)
    15. palette = QPalette()
    16. palette.setColor(QPalette.Window, Qt.blue)
    17. label1.setPalette(palette)
    18. label1.setAlignment(Qt.AlignCenter)
    19. label2.setText("欢迎使用Python GUI应用")
    20. label3.setAlignment(Qt.AlignCenter)
    21. label3.setToolTip('这是一个图片标签')
    22. label3.setPixmap(QPixmap("./1.jpg"))
    23. label4.setText("欢迎访问百度")
    24. label4.setAlignment(Qt.AlignCenter)
    25. label4.setToolTip('这是一个超链接标签')
    26. # 在窗口布局中添加控件
    27. vbox = QVBoxLayout()
    28. vbox.addWidget(label1)
    29. vbox.addStretch()
    30. vbox.addWidget(label2)
    31. vbox.addStretch()
    32. vbox.addWidget(label3)
    33. vbox.addStretch()
    34. vbox.addWidget(label4)
    35. # 允许label控件访问超链接
    36. label1.setOpenExternalLinks(True)
    37. # 打开允许访问超链接
    38. label4.setOpenExternalLinks(False)
    39. # 点击文本框绑定槽事件
    40. label4.linkActivated.connect(link_clicked)
    41. # 滑过文本绑定槽事件
    42. label2.linkHovered.connect(link_hovered)
    43. label1.setTextInteractionFlags(Qt.TextSelectableByMouse)
    44. self.setLayout(vbox)
    45. self.setWindowTitle("QLabel1例子")
    46. def link_hovered():
    47. print("当鼠标滑过label-2标签时,触发事件")
    48. def link_clicked():
    49. print("当用鼠标点击label-4标签时,触发事件")
    50. if __name__ == "__main__":
    51. app = QApplication(sys.argv)
    52. win = WindowDemo()
    53. win.show()
    54. sys.exit(app.exec_())

    运行

    (3)QLineEdit使用

    1. from PyQt5.QtWidgets import QApplication, QLineEdit, QWidget, QFormLayout
    2. import sys
    3. class lineEditDemo(QWidget):
    4. def __init__(self, parent=None):
    5. super(lineEditDemo, self).__init__(parent)
    6. self.setWindowTitle('QLineEdit例子')
    7. flo = QFormLayout()
    8. pNormalLineEdit = QLineEdit()
    9. pNoEchoLineEdit = QLineEdit()
    10. pPasswordLineEdit = QLineEdit()
    11. pPasswordEchoOnEditLineEdit = QLineEdit()
    12. pIPLineEdit = QLineEdit()
    13. pMACLineEdit = QLineEdit()
    14. pDateLineEdit = QLineEdit()
    15. pLicenseLineEdit = QLineEdit()
    16. pIPLineEdit.setInputMask("000.000.000.000;_")
    17. pMACLineEdit.setInputMask("HH:HH:HH:HH:HH:HH;_")
    18. pDateLineEdit.setInputMask("0000-00-00")
    19. pLicenseLineEdit.setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#")
    20. flo.addRow("Normal", pNormalLineEdit)
    21. flo.addRow("NoEcho", pNoEchoLineEdit)
    22. flo.addRow("Password", pPasswordLineEdit)
    23. flo.addRow("PasswordEchoOnEdit", pPasswordEchoOnEditLineEdit)
    24. flo.addRow("数字掩码", pIPLineEdit)
    25. flo.addRow("MAC掩码", pMACLineEdit)
    26. flo.addRow("日期掩码", pDateLineEdit)
    27. flo.addRow("许可证掩码", pLicenseLineEdit)
    28. pNormalLineEdit.setPlaceholderText("Normal")
    29. pNoEchoLineEdit.setPlaceholderText("NoEcho")
    30. pPasswordLineEdit.setPlaceholderText("Password")
    31. pPasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")
    32. # 设置显示效果
    33. pNormalLineEdit.setEchoMode(QLineEdit.Normal)
    34. pNoEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
    35. pPasswordLineEdit.setEchoMode(QLineEdit.Password)
    36. pPasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
    37. self.setLayout(flo)
    38. if __name__ == "__main__":
    39. app = QApplication(sys.argv)
    40. win = lineEditDemo()
    41. win.show()
    42. sys.exit(app.exec_())

    ploty: Plotly Python Graphing Library

     pyqtgraph图像展示

    查看样例代码

    1. import pyqtgraph.examples
    2. pyqtgraph.examples.run()

     安装PyOpenGL:Python安装配置OpenGL环境_idle怎么安装opengl模块_威尔、的博客-CSDN博客

     展示3D图

     

     

     更多拓展Thumbnail gallery — Matplotlib 2.0.2 documentation

     

  • 相关阅读:
    永恒之蓝ms17-010的利用
    【2022 Q2&Q3 华为机试真题 C++】字符串子序列II
    CAN报文的DLC和DataLength的区别
    Chapter9.3:线性系统的状态空间分析与综合(下)
    One bite of Stream(7)
    Debian安装Docker环境
    You must install at least one postgresql-client-<version> package
    代码随想录算法训练营第23期day11 | 20. 有效的括号、1047. 删除字符串中的所有相邻重复项 、150. 逆波兰表达式求值
    android 13.0 SystemUI导航栏添加虚拟按键功能(三)
    基于深度学习的环路滤波和残差缩放
  • 原文地址:https://blog.csdn.net/wj617906617/article/details/133797138