PyQt应用程序在启动后立即关闭

时间:2015-08-21 15:46:45

标签: python pyqt py2exe

我尝试使用 py2exe 从我的脚本中创建 exe 应用程序。问题是如果我通过双击exe文件来运行它,它会在打开后立即关闭。如果我从cmd运行它,它的工作完美。

我试图制作一个table全球但它没有帮助。我已经尝试保留参考 - 没有效果。

以下是GUI的代码,以防它有用:

from PyQt4.QtGui import QTableWidget, QTableWidgetItem,QApplication
import sys
from PyQt4.QtGui import *
import os
from meteo import mesiac,den

class MyTable(QTableWidget):
    def __init__(self, data, *args):
        QTableWidget.__init__(self, *args)
        self.data = data
        self.setmydata()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()

    def setmydata(self):     
        horHeaders = []
        for n, key in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
                     'min tlak','avg teplota','avg vlhkost','avg tlak']):
            horHeaders.append(key)
            for m, item in enumerate(self.data[key]):
                newitem = QTableWidgetItem(str(item))
                self.setItem(m, n, newitem)
        self.setHorizontalHeaderLabels(horHeaders)

        vertical_headers = ['{}.'.format(x+1) for x in xrange(len(self.data.values()[0])-1)]+['Mesiac:']
        self.setVerticalHeaderLabels(vertical_headers)
        self.setWindowTitle('Meteo')

def show_table():
    global table
    table = MyTable(data, len(data.values()[0]), len(data.keys()))
    table.setFixedHeight(len(data.values()[0])*20)
    table.setFixedWidth(len(data.keys())*95)
    table.show()
    return table

if __name__ == '__main__':
    data = {}
    os.system("mode con: cols=100 lines=40")
    filenames = next(os.walk('mesiac'))[2]
    list_of_den = []
    for filename in filenames:
        list_of_den.append(den(filename,filename[:-4]))
    m = mesiac(list_of_den)

    for den in list_of_den:
        for n,attr in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
                     'min tlak','avg teplota','avg vlhkost','avg tlak']):
            try:
                data[attr].append(den.to_list()[n])
            except:
                data[attr]=[den.to_list()[n]]

    m_list = m.to_list()
    for n,attr in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
                     'min tlak','avg teplota','avg vlhkost','avg tlak']):

        try:
            data[attr].append(m_list[n])
        except:
            data[attr]=[m_list[n]]

    app = QApplication(sys.argv)
    t = show_table()
    sys.exit(app.exec_())

当然 - 这是一个setup.py文件:

from distutils.core import setup
import py2exe

options ={"py2exe":{"includes":["sip","PyQt4.QtGui","PyQt4.QtCore","meteo"],"dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"]}}

setup(window=['table.py'],options=options)

如何让它可见?

0 个答案:

没有答案