zoukankan      html  css  js  c++  java
  • Pyqt5的事例讲解

    1、第一个gui程序

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        # 创建一个窗口
        w = QWidget()
    
        # 设置窗口的高度和宽度
        w.resize(500,200)
    
        # 移动窗口的位置
        w.move(400,100)
    
        # 设置窗口的title
        w.setWindowTitle("第一个gui程序")
    
        # 显示窗口
        w.show()
    
        # 设置窗口退出,程序在退出
        sys.exit(app.exec_())
    

      

    2、设置图标

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    
    
    # 设置图标的类
    from PyQt5.QtGui import QIcon
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        # 创建一个窗口
        w = QWidget()
    
        # 设置窗口的高度和宽度
        w.resize(500,200)
    
        # 移动窗口的位置
        w.move(400,100)
    
        # 设置窗口的title
        w.setWindowTitle("第一个gui程序")
    
    
        # 设置窗口的图标
        w.setWindowIcon(QIcon("test.jpg"))
    
    
        # 显示窗口
        w.show()
    
        # 设置窗口退出,程序同时退出
        sys.exit(app.exec_())
    

      

    3、设置窗口的浮动提示框和按钮的浮动提示框

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtGui import QIcon
    
    
    # 处理提示框的一个类
    from PyQt5.QtWidgets import QToolTip
    
    # 处理按钮的一个类
    from PyQt5.QtWidgets import QPushButton
    
    # 处理字体的一个类
    from PyQt5.QtGui import QFont
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        # 创建一个窗口
        w = QWidget()
    
        # 设置窗口的高度和宽度
        w.resize(500,200)
    
        # 移动窗口的位置
        w.move(400,100)
    
        # 设置窗口的title
        w.setWindowTitle("提示框")
    
    
        # 设置窗口的图标
        w.setWindowIcon(QIcon("test.jpg"))
    
        # 创建窗口的提示文本信息
        w.setToolTip("这是一个窗口的提示框
    设计者:张三")
    
        # 设置字体和字号
        QToolTip.setFont(QFont("SansSerif", 15))
    
        # 创建一个按钮,这个按钮防在我们前面创建的窗口中
        b = QPushButton("Button",w)
    
        # 设置按钮的提示文本信息
        b.setToolTip("这是一个按钮的提示框
    设计者:张三")
    
        # 改变按钮的尺寸
        b.resize(b.sizeHint())
    
        # 移动按钮
        b.move(50,50)
        # 显示窗口
        w.show()
    
    
        # 设置窗口退出,程序在退出
        sys.exit(app.exec_())
    

      

    4、设置一个按钮,点击该按钮会关闭整个窗口的效果

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtGui import QIcon
    
    
    # 处理提示框的一个类
    from PyQt5.QtWidgets import QToolTip
    
    # 处理按钮的一个类
    from PyQt5.QtWidgets import QPushButton
    
    # 处理字体的一个类
    from PyQt5.QtGui import QFont
    
    
    # 需要导入一个新的模块
    from PyQt5.QtCore import QCoreApplication
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        # 创建一个窗口
        w = QWidget()
    
        # 设置窗口的高度和宽度
        w.resize(500,200)
    
        # 移动窗口的位置
        w.move(400,100)
    
        # 设置窗口的title
        w.setWindowTitle("关闭窗口测试")
    
    
        # 设置窗口的图标
        w.setWindowIcon(QIcon("test.jpg"))
    
        # 创建窗口的提示文本信息
        w.setToolTip("这是一个窗口的提示框
    设计者:崔跃荣")
    
        # 设置字体和字号
        QToolTip.setFont(QFont("SansSerif", 15))
    
        # 创建一个按钮,这个按钮防在我们前面创建的窗口中
        b = QPushButton("点击关闭窗口",w)
    
        # 设置按钮的提示文本信息
        b.setToolTip("这是一个关闭按钮的提示框
    设计者:崔跃荣")
    
        # 为这个按钮绑定一个事件
        b.clicked.connect(QCoreApplication.instance().quit)
    
    
        # 改变按钮的尺寸
        b.resize(b.sizeHint())
    
        # 移动按钮
        b.move(50,50)
        # 显示窗口
        w.show()
    
    
        # 设置窗口退出,程序在退出
        sys.exit(app.exec_())
    

      

    5、做个捕获关闭事件的对话框

    # 重写QWidget类中的窗口关闭事件,先捕获窗口的关闭的事件,然后在进行判断
    import sys
    
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QApplication
    
    
    # 封装窗口代码的类
    class Mymessagebox(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            self.setGeometry(300,300,300,300)
            self.setWindowTitle("对话框")
            self.show()
    
        # 重写窗口关闭事件
        def closeEvent(self,event):
            # 显示询问的对话框,这里会阻塞
    
            # 显示两个框,一个是YES 一个NO,默认选中no
            reply = QMessageBox.question(self,"消息","确定要退出?",QMessageBox.Yes | QMessageBox.No,QMessageBox.No)
    
            if reply == QMessageBox.Yes:
    
                # 接受事件
                event.accept()
            else:
                # 忽略事件
                event.ignore()
    

    6、做一个窗口居中的示例

    # 通过得到屏幕宽度和高度和窗口的高度和宽度来计算得到居中的位置
    
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    import sys
    
    class Centerwindowbox(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            self.resize(300,200)
            self.setWindowTitle("窗口居中的对话框")
            self.center()
            self.show()
    
        def center(self):
            desktop = app.desktop()
            # print(dir(desktop))
    
            # 获取整个屏幕的高度
            print(desktop.height())
    
            # 获取整个屏幕的宽度
            print(desktop.width())
    
            # 获取窗口的宽度
            print(self.width())
    
            # 获取窗口的高度
            print(self.height())
            self.move((desktop.width() - self.width())/2,(desktop.height() - self.height())/2)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        cw = Centerwindowbox()
        sys.exit(app.exec_())
    

    7、做一个绝对布局的例子

    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QLabel
    import sys
    
    
    class Test(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            label1 = QLabel("姓名",self)
            label1.move(15,20)
            label2 = QLabel("年龄", self)
            label2.move(25,30)
            label3 = QLabel("身高", self)
            label3.move(35,40)
    
            self.setGeometry(300,200,400,400)
            self.setWindowTitle("窗口绝对布局")
            self.show()
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        w = Test()
        sys.exit(app.exec_())
    

    8、做一个盒布局的例子

    # 水平盒布局和垂直盒布局,有更强的适应性,会随着窗口的尺寸的变化,位置也会变化,绝对布局,如果窗口的尺寸变化,控件的位置是不会变化的
    
    # 水平盒布局:沿水平方向摆放
    
    # 垂直盒布局:沿垂直方向摆放
    
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QPushButton
    
    
    # 用到的新类
    from PyQt5.QtWidgets import QHBoxLayout
    from PyQt5.QtWidgets import QVBoxLayout
    import sys
    
    
    
    # 我们这个例子是把两个控件放在水平盒布局中,然后把水平盒布局放在垂直盒布局中
    
    class Boxlagout(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            # 创建2个按钮
            button1 = QPushButton("确定")
            button2 = QPushButton("取消")
    
    
            # 创建水平盒布局
            hbox = QHBoxLayout()
            vbox = QVBoxLayout()
    
            # 将水平盒布局放在窗口的右侧
            hbox.addStretch()
    
            # 把两个按钮添加到水平盒布局中
            hbox.addWidget(button1)
            hbox.addWidget(button2)
    
            # 将垂直盒布局放在窗口的下边
            vbox.addStretch()
    
            # 把水平盒布局添加到垂直盒布局中
            vbox.addLayout(hbox)
    
            # 让垂直盒布局生效,这样操作,水平盒布局也会同时生效
            self.setLayout(vbox)
            self.setGeometry(300,200,400,400)
            self.setWindowTitle("盒布局")
            self.show()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = Boxlagout()
    
        sys.exit(app.exec_())
    

      

    9、做一个网格布局的例子

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QPushButton
    
    
    # 用到的新类
    from PyQt5.QtWidgets import QLabel
    from PyQt5.QtWidgets import QLineEdit
    from PyQt5.QtWidgets import QTextEdit
    from PyQt5.QtWidgets import QGridLayout
    
    
    class Test(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
    
            title = QLabel("标题")
            auther = QLabel("作者")
            summary = QLabel("摘要")
    
            titleedit = QLineEdit()
            autheredit = QLineEdit()
            summaryedit = QTextEdit()
    
            # 创建网格布局的对象
            grid = QGridLayout()
    
            # 创建单元格之间的距离
            grid.setSpacing(20)
    
            # 添加到第二行的第一列
            grid.addWidget(title,1,0)
    
            # 添加到第二行的第二列
            grid.addWidget(titleedit,1,1)
    
            # 添加到第三行第一列
            grid.addWidget(auther,2,0)
    
            # 添加到第三行第二列
            grid.addWidget(autheredit,2,1)
    
            grid.addWidget(summary,3,0)
    
            # 占据(3,1)(4,1)(5,1)(6,1)
            grid.addWidget(summaryedit,3,1,6,1)
    
    
    
            # 应用当前的网格布局
            self.setLayout(grid)
    
    
            self.setGeometry(300,200,400,400)
            self.setWindowTitle("网格布局")
            self.show()
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = Test()
    
        sys.exit(app.exec_())
    

      

    10、做一个按钮空间的例子

    # 按钮支持两种状态,一种是normal,一种是checked
    # normal:按钮正常的状态
    # checked:按钮被按下的状态
    
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QPushButton
    
    
    # 用到新的类
    from PyQt5.QtWidgets import QFrame
    
    
    # 设置颜色的类
    from PyQt5.QtGui import QColor
    
    
    
    class Test(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            # 创建初始的颜色,黑色
            self.color = QColor(0,0,0)
    
            # 创建红色的按钮
            redbutton = QPushButton("红",self)
    
            # 设置按钮被选中
            redbutton.setCheckable(True)
    
            # 用绝对定位
            redbutton.move(10,10)
    
            # 点击会执行self.setColor的函数
            redbutton.clicked[bool].connect(self.setColor)
    
    
            # 创建绿色的按钮
            greenbutton = QPushButton("绿", self)
    
            # 设置按钮被选中
            greenbutton.setCheckable(True)
    
            # 用绝对定位
            greenbutton.move(10, 30)
    
            # 点击会执行self.setColor的函数
            greenbutton.clicked[bool].connect(self.setColor)
    
    
    
            # 创建蓝色的按钮
            bluebutton = QPushButton("蓝", self)
    
            # 设置按钮被选中
            bluebutton.setCheckable(True)
    
            # 用绝对定位
            bluebutton.move(10, 50)
    
            # 点击会执行self.setColor的函数
            bluebutton.clicked[bool].connect(self.setColor)
    
    
    
    
            # 创建显示颜色的对象
            self.square = QFrame(self)
            # 设置尺寸
            self.square.setGeometry(150,20,100,100)
    
    
            # 设置背景颜色
            self.square.setStyleSheet('QWidget{background-color:%s}'%self.color.name())
    
            self.setGeometry(300,200,400,400)
            self.setWindowTitle("按钮控件")
            self.show()
    
        def setColor(self,presssed):
            # presssed这个参数的意思是当前的按钮是否被按下
    
            # 获取当前点击的按钮
            source = self.sender()
    
            if presssed:
                var = 255
            else:
                var = 0
            if source.text() == "红":
                self.color.setRed(var)
            elif source.text() == "绿":
                self.color.setGreen(var)
            else:
                self.color.setBlue(var)
            self.square.setStyleSheet('QWidget{background-color:%s}'%self.color.name())
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = Test()
    
        sys.exit(app.exec_())
    

      

    11、编写一个QlineEdit控件的例子,单行文本输入框

    # 这个例子是这样的,我们定义个lable控件,然后在定义QlineEdit控件,然后对QlineEdit控件绑定一个onchange的方法,这个方法就是获取
    # QlineEdit控件输入的值,然后把这个值赋值给label标签
    
    import sys
    
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QLabel
    from PyQt5.QtWidgets import QLineEdit
    from PyQt5.QtWidgets import QApplication
    
    class LineEdit(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            self.label = QLabel(self)
            lineEdit = QLineEdit(self)
            lineEdit.move(80,100)
            self.label.move(80,40)
    
            # 对lineEdit绑定一个changed事件
            lineEdit.textChanged[str].connect(self.onChanged)
    
            self.setGeometry(300,200,280,200)
    
            self.setWindowTitle("QlineEdit控件")
            self.show()
    
        def onChanged(self,text):
            self.label.setText(text)
            self.label.adjustSize()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = LineEdit()
    
        sys.exit(app.exec_())
    

      

    12、写一个Checkbox的例子

    # Checkbox:复选框
    # 这个例子是这样的,先一个复选框,然后监控这个复选框的是否改变,如果选中,设置窗口的title为A,如果未选中,则设置窗口的title为B
    import sys
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QCheckBox
    from PyQt5.QtCore import Qt
    
    
    class Checkbox(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            cb = QCheckBox("请选择",self)
            cb.move(20,20)
    
            # 复选框状态改变,就会触发执行self.changeTitle这个方法,同时会把复选框的说法选中的状态传递到self.changeTitle这个方法中
            cb.stateChanged.connect(self.changeTitle)
    
            self.setGeometry(100,200,300,200)
    
            self.setWindowTitle("还没有选择我")
            self.show()
    
        # Qt.Checked 这个是布尔类型
        def changeTitle(self,state):
            if state == Qt.Checked:
                self.setWindowTitle("已结选择了")
            else:
                self.setWindowTitle("还没有选择")
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = Checkbox()
    
        sys.exit(app.exec_())
    

      

    13、写一个Qslider滑块控件的例子

    # QSlider:滑块控件,我们这里做一个这样的例子,写一个滑块,设置这个滑块最大值和最小值,然后监控这个滑块的valuechange事件,然后把滑块的value的值
    # 赋值给一个lable标签
    
    
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QLabel
    from PyQt5.QtWidgets import QSlider
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtCore import Qt
    
    class slider(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            # Qt.Horizontal:这个的意思是水平显示
            # Vertical:这个意思是垂直显示
            # slider = QSlider(Qt.Horizontal,self)
            slider = QSlider(Qt.Vertical, self)
    
            slider.setMinimum(60)
            slider.setMaximum(300)
            slider.setGeometry(30,40,50,300)
    
            slider.valueChanged[int].connect(self.changevalue)
            self.label = QLabel(self)
            self.label.setGeometry(160,40,80,30)
            self.setGeometry(100,200,300,1000)
            self.setWindowTitle("QSlider控件")
            self.show()
        def changevalue(self,value):
            self.label.setText(str(value))
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        b = slider()
    
        sys.exit(app.exec_())
    

      

    14、pyqt实现一个进度条的示例

    #Auther Bob
    #--*--conding:utf-8 --*--
    import sys
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QProgressBar
    from PyQt5.QtWidgets import QPushButton
    from PyQt5.QtWidgets import QApplication
    
    # 定时器
    from PyQt5.QtCore import QBasicTimer
    
    class ProgressBar(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
        def initUI(self):
            self.pbar = QProgressBar(self)
            self.pbar.setGeometry(40,40,400,40)
            self.btn = QPushButton("开始",self)
            self.btn.move(40,80)
            self.btn.clicked.connect(self.doAction)
    
            self.timer = QBasicTimer()
            self.value = 0
            self.setGeometry(300,300,500,500)
            self.setWindowTitle("进度条控件")
            self.show()
        def timerEvent(self, *args, **kwargs):
            if self.value >= 100:
                self.timer.stop()
                self.btn.setText("完成")
                return
            else:
                self.value += 1
                self.pbar.setValue(self.value)
        def doAction(self):
            if self.timer.isActive():
                self.timer.stop()
                self.btn.setText("开始")
            else:
                self.timer.start(100,self)
                self.btn.setText("停止")
                # self.timer.stop()
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = ProgressBar()
        sys.exit(app.exec_())
    

      

    15、Pyqt实现一个下拉菜单的例子

    #Auther Bob
    #--*--conding:utf-8 --*--
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QLabel
    from PyQt5.QtWidgets import QComboBox
    
    class ComboBox(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            self.lab = QLabel("中国",self)
            self.lab.move(50,150)
            combo = QComboBox(self)
            combo.addItem("米国")
            combo.addItem("法国")
            combo.addItem("德国")
            combo.addItem("英国")
            combo.move(50,50)
    
            combo.activated[str].connect(self.onactived)
    
            combo1 = QComboBox(self)
    
            combo1 = QComboBox(self)
            combo1.addItem("深圳")
            combo1.addItem("背景")
            combo1.addItem("上海")
            combo1.addItem("广州")
            combo1.move(200,50)
            combo1.activated[str].connect(self.onactived)
            self.setGeometry(300,300,300,200)
    
            self.setWindowTitle("下拉菜单")
    
            self.show()
    
        def onactived(self,text):
            self.lab.setText(text)
            self.lab.adjustSize()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = ComboBox()
        sys.exit(app.exec_())
    

      

    16、pyqt实现一个现实图像的例子

    #Auther Bob
    #--*--conding:utf-8 --*--
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QHBoxLayout
    from PyQt5.QtWidgets import QLabel
    
    from PyQt5.QtGui import QPixmap
    
    class Pixmap(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            hbox = QHBoxLayout(self)
    
            pixmap = QPixmap("test.JPG")
    
            lab = QLabel(self)
    
            lab.setPixmap(pixmap)
    
            hbox.addWidget(lab)
    
    
            self.setLayout(hbox)
    
            self.move(300,300)
    
            self.setWindowTitle("显示图像")
            self.show()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = Pixmap()
        sys.exit(app.exec_())
    

      

    17、pyqt实现一个显示日历的例子

    #Auther Bob
    #--*--conding:utf-8 --*--
    
    "日历控件"
    
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QLabel
    from PyQt5.QtWidgets import QCalendarWidget
    from PyQt5.QtWidgets import QVBoxLayout
    
    from PyQt5.QtCore import QDate
    
    
    class CalendarWidget(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            vbox = QVBoxLayout()
            cal = QCalendarWidget(self)
            self.lab = QLabel(self)
    
            # 显示网个
            cal.setGridVisible(True)
    
            cal.clicked[QDate].connect(self.showdate)
    
            vbox.addWidget(cal)
    
            date = cal.selectedDate()
    
            self.lab.setText(date.toString())
    
            vbox.addWidget(self.lab)
    
            self.setLayout(vbox)
    
            self.setGeometry(300,300,350,300)
            self.setWindowTitle("日历控件")
            self.show()
    
    
        def showdate(self,data):
            self.lab.setText(data.toString())
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = CalendarWidget()
        sys.exit(app.exec_())
    

      

    18、pyqt实现一个显示菜单的例子

    #Auther Bob
    #--*--conding:utf-8 --*--
    
    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtWidgets import QLabel
    
    from PyQt5.QtWidgets import QMainWindow
    from PyQt5.QtWidgets import QAction
    from PyQt5.QtWidgets import QMenu
    
    
    class Menu(QMainWindow):
    
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            menubar = self.menuBar()
            fileMenu = menubar.addMenu("文件")
            newAction = QAction("新建",self)
            importMenu = QMenu("导入",self)
            importAction1 = QAction("从pdf导入",self)
            importAction2 = QAction("从word导入", self)
            importAction1.triggered.connect(self.actionHandler1)
            importAction2.triggered.connect(self.actionHandler2)
    
            importMenu.addAction(importAction1)
            importMenu.addAction(importAction2)
    
            fileMenu.addAction(newAction)
            fileMenu.addMenu(importMenu)
    
            self.setGeometry(300,300,300,200)
            self.setWindowTitle("菜单")
            self.show()
        def actionHandler1(self):
            print("从pdf导入")
        def actionHandler2(self):
            print("从word导入")
    
    
    
    if __name__ == '__main__':
    
        app = QApplication(sys.argv)
        form = Menu()
        sys.exit(app.exec_())
    

      

  • 相关阅读:
    BZOJ 1150 [CTSC2007]数据备份Backup(贪心+优先队列)
    BZOJ 1053 [HAOI2007]反素数ant(约数个数)
    BZOJ 1066 [SCOI2007]蜥蜴(最大流)
    CodeForces 772A Voltage Keepsake
    HDU 6030 Happy Necklace
    HDU 6031 Innumerable Ancestors
    HDU 6026 Deleting Edges
    HDU 6024 Building Shops
    HDU 6029 Graph Theory
    HDU 6025 Coprime Sequence
  • 原文地址:https://www.cnblogs.com/bainianminguo/p/9951276.html
Copyright © 2011-2022 走看看