1.转换ui文件为python文件,举例:my.ui
pyuic4 -o my.py my.ui
2. 运行程序代码
# -*- coding:utf-8-*-
import sys
from my import Ui_MainWindow
from PyQt4 import QtGui
from PIL import Image
from PyQt4.QtGui import *
from PyQt4.QtCore import QString
class ImageWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.setWindowIcon(QtGui.QIcon('long.png'))
self.textEdit.append(" ==================================")
self.textEdit.append(" || ZHENG WEN 2016-11-18 ||")
self.textEdit.append(" ==================================")
self.arr = None
self.pushButton.clicked.connect(self.buttonClicked)
def buttonClicked(self):
self.textEdit.append("success")
def main():
app = QtGui.QApplication(sys.argv)
iw = ImageWindow()
iw.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
3.运行即可
4.安装pyinstaller,打包
pyinstaller -w --onefile --icon="my.ico" demo.py (打包为一个文件,我这样打包的之后,经常运行不成功)
pyinstaller -w --icon="my.ico" demo.py (打包之后一堆文件,运行正常)