我正在尝试冻结一个python程序,它只是一个菜单,可以选择运行其他python脚本。我正在使用子进程在主程序(菜单)中运行每个脚本选项。程序本身运行正常,但是当我尝试使用cx_freeze创建可执行文件时,创建过程似乎被中断,并且生成的.exe文件不会运行任何子进程。我试图使用其他方法来调用所选的python脚本,例如os和call,但不能让它们工作。请帮助我,以便我可以获得一个有效的.exe文件。这是使用子进程的主脚本的一部分:
import tkinter as tk
from tkinter import Frame, Button, Label
import subprocess
import sys
import os
class menu(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.mymaster = master
self.widgets()
def widgets(self):
self.menu_container()
self.fill0_frame()
self.title()
self.bottom_frame()
self.play_or_quit())
def menu_container(self):
self.menu_container = tk.Toplevel(self)
...
...
....
def play_or_quit(self):
self.play_or_quit = Frame(self.bottom_frame,width=100,background="grey")
self.play_or_quit.grid(row=2,column=5)
self.button1 = tk.Button(self.play_or_quit, command = import_cw2)
self.button1_name = "childwindow2"
self.button1.configure(text=self.button1_name, background="violet",width=16)
self.button1.grid(row=17,column=10,sticky = "ES")
self.button2 = tk.Button(self.play_or_quit, command = import_cwp4)
self.button2_name = "childwindowprimes4"
self.button2.configure(text=self.button2_name, background="pink",width=16)
self.button2.grid(row=18,column=10,sticky = "ES")
self.button3 = Button(self.play_or_quit, command = import_TSF) #height=1,width=2)
self.button3_name = "The Seiji Factor"
self.button3.configure(text=self.button3_name, background="tan",width=16)
self.button3.grid(row=19,column=10,sticky = "ES")
self.button4 = Button(self.play_or_quit, command = self.finished, height=1,width=2)
self.button4_name = "Quit"
self.button4.configure(text=self.button4_name, background="red",width=16)
self.button4.grid(row=20,column=10,sticky= "ES")
...
def import_cw2(): #,event
theproc = subprocess.Popen([sys.executable, "cw2gameframes.py"])
theproc.communicate()
def import_cwp4():
theproc2 = subprocess.Popen([sys.executable, "cwp4gameframes.py"])
theproc2.communicate()
def import_TSF():
theproc = subprocess.Popen([sys.executable, "SeijiFactorgameframes.py"])
theproc.communicate()
if __name__=='__main__':
root = tk.Tk()
root.withdraw()
application = menu(root)
root.mainloop()