zoukankan      html  css  js  c++  java
  • Python——GUI编程(python programming)

    Python——GUI编程(python programming)

    import sys
    from math import *
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    
    class Form(QDialog):
        def __init__(self,parent=None):
            super().__init__(parent)
            
            layout = QVBoxLayout()
            
            self.setLayout(layout)
            
        def updateUi(self):
            pass
    
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    app.exec_()

    QLabel

    import sys
    from math import *
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    
    class Form(QDialog):
        def __init__(self,parent=None):
            super().__init__(parent)
    
            #标签
            self.aLabel = QLabel(self)
            self.aLabel.setText("hhhhhhh")
    
            #数字框
            self.mySpinBox = QDoubleSpinBox(self)
            self.mySpinBox.setValue(100)
            self.mySpinBox.setRange(1,1000)
    
            #滑动条
            self.s = QSlider()
    
            #可编辑文本
            self.lineedit = QLineEdit("请输入我爱帅帅:")
    
            #不可编辑文本框
            self.browser = QTextBrowser()
            self.browser.append("你改不了吧,嘿嘿")
    
            #选单
            self.listWidget = QListWidget(self)
            self.listWidget.addItems(["巧克力","抹茶","冰淇淋"])
    
            #下拉选单
            self.comboBox = QComboBox(self)
            itemdata = ['学习python','学习c++','学习java']
            self.comboBox.addItems(itemdata)
    
            #按钮
            self.okButton = QPushButton(self)
            self.okButton.setText("我佛了...")
            
            layout = QVBoxLayout()
            layout.addWidget(self.aLabel)
            layout.addWidget(self.mySpinBox)
            layout.addWidget(self.s)
            layout.addWidget(self.lineedit)
            layout.addWidget(self.browser)
            layout.addWidget(self.listWidget)
            layout.addWidget(self.comboBox)
            layout.addWidget(self.okButton)
            
            self.setLayout(layout)
            
        def updateUi(self):
            pass
    
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    app.exec_()

     set_pen

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    
    class PenPropertiesDlg(QDialog):
        def __init__(self, parent=None):
            super(PenPropertiesDlg, self).__init__(parent)
            
            widthLabel = QLabel("&Width:")
            self.widthSpinBox = QSpinBox()
            widthLabel.setBuddy(self.widthSpinBox)
            
            self.widthSpinBox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
            self.widthSpinBox.setRange(0, 24)
            self.beveledCheckBox = QCheckBox("&Beveled edges")
            
            styleLabel = QLabel("&Style:")
            self.styleComboBox = QComboBox()
            styleLabel.setBuddy(self.styleComboBox)
            self.styleComboBox.addItems(["Solid", "Dashed", "Dotted", "DashDotted", "DashDotDotted"])
    
            okButton = QPushButton("&OK")
            cancelButton = QPushButton("Cancel")
    
            buttonLayout = QHBoxLayout()
            buttonLayout.addStretch()
            buttonLayout.addWidget(okButton)
            buttonLayout.addWidget(cancelButton)
            layout = QGridLayout()
            layout.addWidget(widthLabel, 0, 0)
            layout.addWidget(self.widthSpinBox, 0, 1)
            layout.addWidget(self.beveledCheckBox, 0, 2)
            layout.addWidget(styleLabel, 1, 0)
            layout.addWidget(self.styleComboBox, 1, 1, 1, 2)
            layout.addLayout(buttonLayout, 2, 0, 1, 3)
            self.setLayout(layout)
            self.setWindowTitle("Pen Properties")
    
            okButton.clicked.connect(self.accept)
            cancelButton.clicked.connect(self.reject)
    
    
    class Form(QDialog):
        def __init__(self, parent=None):
            super(Form, self).__init__(parent)
            self.width = 1
            self.beveled = False
            self.style = "Solid"
    
            penButton = QPushButton("Set Pen")
            self.label = QLabel("The Pen has not been set")
            self.label.setTextFormat(Qt.RichText)
            layout = QVBoxLayout()
            layout.addWidget(penButton)
            layout.addWidget(self.label)
            self.setLayout(layout)
            self.setWindowTitle("Pen")
            penButton.clicked.connect(self.setPenProperties)
            self.updateData()
    
        def updateData(self):
            bevel = ""
            if self.beveled:
                bevel = "<br>Beveled"
            self.label.setText("Width = {}<br>Style = {}{}".format(self.width, self.style, bevel))
    
        def setPenProperties(self):
            dialog = PenPropertiesDlg(self)
            dialog.widthSpinBox.setValue(self.width)
            dialog.beveledCheckBox.setChecked(self.beveled)
            dialog.styleComboBox.setCurrentIndex(
                    dialog.styleComboBox.findText(self.style))
            if dialog.exec_():
                self.width = dialog.widthSpinBox.value()
                self.beveled = dialog.beveledCheckBox.isChecked()
                self.style = dialog.styleComboBox.currentText()
                self.updateData()
    
    
    app = QApplication(sys.argv)
    form = Form()
    form.resize(400, 200)
    form.show()
    app.exec_()
    View Code

  • 相关阅读:
    让一个 csproj 项目指定多个开发框架
    推荐近乎免费的调试神器——OzCode
    再也不用克隆多个仓库啦!git worktree 一个 git 仓库可以连接多个工作目录
    .NET Core 和 .NET Framework 中的 MEF2
    将 WPF、UWP 以及其他各种类型的旧样式的 csproj 文件迁移成新样式的 csproj 文件
    .NET 中的轻量级线程安全
    卡诺模型(KANO Model)
    C#/.NET 匿名函数会捕获变量,并延长对象的生命周期
    迫不及待地体验了一把 C#8.0 中的可空引用类型(Nullable Reference)
    异步任务中的重新进入(Reentrancy)
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270769.html
Copyright © 2011-2022 走看看