可运行的最简窗口代码
# -*- 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()

返回值是文件的完整路径

posted on 2013-08-13 12:25  V42  阅读(230)  评论(0编辑  收藏  举报