zoukankan      html  css  js  c++  java
  • pyQt开发笔记

    可运行的最简窗口代码
    # -*- coding: utf-8 -*-
    #! /usr/bin/env python
    
    import sys
    from PyQt4 import QtGui, QtCore
    
    class ImageViewer(QtGui.QMainWindow):
        def __init__(self):
            print 'Pillars Image Viewer'
            super(ImageViewer, self).__init__()
            
            self.setGeometry(QtCore.QRect(100, 100, 100, 100))
    
            self.setWindowTitle('simple')
    
    def main():
        app = QtGui.QApplication(sys.argv)
        imageViewer = ImageViewer()
        imageViewer.show()
        sys.exit(app.exec_())
        
    if __name__ == '__main__':
        main()


    把Qt设计器生成的ui文件转换为.py格式
    pyuic4 -o ui_xxx.py xxx.ui
    转换后的py文件的调用方法.
    class Widget(QtGui.QMainWindow):
        def __init__(self,parent=None):
            QtGui.QWidget.__init__(self,parent)
            self.loginGui()
        def loginGui(self):
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            self.show()


    实际.ui文件可以不用转换可直接被程序引用
    self.ui = uic.loadUi('DailyClient.ui')
    # -*- coding: utf-8 -*-
    #! /usr/bin/env python
    
    from PyQt4 import QtGui, uic
    import sys
    
    class Widget(QtGui.QWidget):
        def __init__(self, parent=None):
            QtGui.QWidget.__init__(self, parent)
            self.ui = uic.loadUi('DailyClient.ui')
            self.ui.show()
            
            self.ui.IssueButton.clicked.connect(self.onIssueButttonClicked)
            
        def onIssueButttonClicked(self):
            print 'IssueButttonClicked'
            
    def main():
        app = QtGui.QApplication(sys.argv)
        widget = Widget()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()

    文件打开对话框

    QtGui.QFileDialog.getOpenFileName()

    返回值是文件的完整路径

  • 相关阅读:
    Python获取会议部分的信息内容(不断完善中)
    TensorFlow学习笔记(UTF-8 问题解决 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)
    Tensorflow学习笔记(对MNIST经典例程的)的代码注释与理解
    virtualenvwrapper
    最小二乘法与梯度下降的区别
    Git
    Jupyter
    Linux
    Iterm2
    Homebrew
  • 原文地址:https://www.cnblogs.com/viator42/p/3252430.html
Copyright © 2011-2022 走看看