zoukankan      html  css  js  c++  java
  • Python——GUI可视化

     1 import sys
     2 from PyQt5.QtCore import *
     3 from PyQt5.QtGui import *
     4 from PyQt5.QtWidgets import *
     5 
     6 class Form(QDialog):
     7     def __init__(self,parent=None):
     8         super().__init__(parent)
     9         #窗体标题
    10         self.setWindowTitle('窗体标题!')
    11         #QLabel标签
    12         self.aLabel = QLabel(self)
    13         self.aLabel.setText('ABCD')
    14         #QSpinBox数字框
    15         self.mySpinBox = QDoubleSpinBox(self)
    16         self.mySpinBox.setValue(100)
    17         self.mySpinBox.setRange(1,666)
    18         #滑动条
    19         self.s = QSlider()
    20         #QListWidget选单
    21         self.listWidget = QListWidget(self)
    22         self.listWidget.addItems(['item1','item2','item3'])
    23         #QPushButton按钮
    24         self.okButton = QPushButton(self)
    25         self.okButton.setText("OK")
    26         #可编辑文本框
    27         self.lineedit = QLineEdit("Type a string!")
    28         #不可编辑文本框
    29         self.browser = QTextBrowser()
    30         self.browser.append('abcd')
    31         #下拉选单
    32         self.comboBox = QComboBox(self)
    33         itemdata = ['a','b','c']
    34         self.comboBox.addItems(itemdata)
    35 
    36         
    37         layout = QVBoxLayout()
    38         layout.addWidget(self.aLabel)
    39         layout.addWidget(self.mySpinBox)
    40         layout.addWidget(self.s)
    41         layout.addWidget(self.listWidget)
    42         layout.addWidget(self.okButton)
    43         layout.addWidget(self.lineedit)
    44         layout.addWidget(self.browser)
    45         layout.addWidget(self.comboBox)
    46         self.setLayout(layout)
    47     
    48 #下面这段脚本在PyQt GUI编程中几乎通用的        
    49 app = QApplication(sys.argv)
    50 form = Form()
    51 form.show()
    52 app.exec_()

    输出结果:

  • 相关阅读:
    数据库索引(Oracle和Mysql)学习总结
    个人开源Git地址
    关于SQL优化这些你了解吗?
    Java项目排查cpu负载高
    Java Bean与Map之间相互转化的实现
    Maven项目改为spring boot项目的方法
    spring boot从redis取缓存发生java.lang.ClassCastException异常
    MySQL优化之Explain命令解读
    阿里巴巴校招四面经验分享
    HDBS之应用代码优化
  • 原文地址:https://www.cnblogs.com/wwwwwei/p/10820460.html
Copyright © 2011-2022 走看看