使用 cx_freeze 冻结我的 Python 程序后,我尝试运行创建的 exe 文件,但它没有运行。
电话簿.py
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtUiTools import *
class PhoneBook:
i=0;
def __init__(self):
loader = QUiLoader();
file = QFile("PhoneBook.ui");
file.open(QFile.ReadOnly);
self.ui = loader.load(file);
file.close();
self.ui.setWindowIcon(QIcon('web.png'));
self.ui.pushButton.clicked.connect(self.add);
self.ui.pushButton_2.clicked.connect(self.load);
def __del__ ( self ):
self.ui = None;
def add(self):
loader1 = QUiLoader();
file1 = QFile("Add.ui");
file1.open(QFile.ReadOnly);
self.ui2 = loader1.load(file1);
file1.close();
self.ui2.show();
self.ui2.pushButton.clicked.connect(self.get);
def show(self):
self.ui.show();
def clear1(self):
self.ui.lineEdit.clear();
def get(self):
name1 = self.ui2.lineEdit.text();
name2 = self.ui2.lineEdit_2.text();
f = open('data','a' );
f.write(name1);
f.write('#');
f.write(name2);
f.write('\n');
f.close();
self.load();
self.ui2.close();
def load(self):
f = open('data', 'r');
for i in range(0, 10):
string = f.readline();
l=len(string);
print(string);
print(l);
for c in range(0, l-1):
if string[c]=="#":
break;
print(c);
name1=string[0:c];
name2=string[c+1:l-1];
self.ui.tableWidget.setItem(i, 0, QTableWidgetItem(name1));
self.ui.tableWidget.setItem(i, 1, QTableWidgetItem(name2));
i =i+1;
def sort(self):
f=open('data', 'r');
f.readlines().sort();
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setApplicationName('PhoneBook Application')
w = PhoneBook();
w.show();
QObject.connect(app, SIGNAL('lastWindowClosed()'), app,SLOT('quit()'))
sys.exit(app.exec_())
安装程序.py
import sys
from cx_Freeze import setup,Executable
includefiles = ['Add.ui', 'PhoneBook.ui', 'data', 'web.png']
includes = ["re"]
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="PhoneBook", version="3.0",description="Test",options = {'build_exe': {'include_files':includefiles, 'includes' : includes}
是因为我使用的是 QUILoader 吗?然而,在直接执行 Python 代码时,它会显示正确的结果。请帮我。