使用py2exe,我能够成功地将许多单独的python文件分成许多单独的.exe文件,然后运行.exe程序。然后我将所有这些.exe文件放入python GUI。 GUI将在Combobox中显示我的所有exe文件。
从Combobox中,用户可以选择要打开的单个.exe文件,然后运行.exe文件。
我能够让我的GUI作为python程序运行。当用户选择.exe文件时,.exe文件运行,但我将GUI转换为.exe程序,它将不再运行用户选择的.exe文件。
这是我的GUI应用程序代码,它将我的所有.exe文件放入Combobox。
import os
from tkinter import *
from tkinter.ttk import *
class Parking_Gui(Frame):
def __init__(self):
"""Sets up the window and widgets"""
Frame.__init__(self)
self.master.geometry("325x125")
self.master.title("MSU PARKING APP")
self.master.rowconfigure(0, weight = 1)
self.master.columnconfigure(0, weight = 1)
self.grid(sticky = N)
# Label for the parking lots
self._LotLabel = Label(self, text = "MSU Parking")
self._LotLabel.grid(row = 0, column = 0)
# Combo Box for individual exe program added to Combobox
self._ComboValue = StringVar()
self._LotCombo = Combobox(self, textvariable=self._ComboValue,
state='readonly', height = '5',
justify = 'center')
self._LotCombo['values'] = 'BURG.exe' //the exe app
self._LotCombo.grid(row = 0, column = 1)
# Button to open word file
self._button = Button(self, text = "Open", command = self._openFile)
self._button.grid(row = 0, column = 2)
def _openFile(self):
"""Event handler for the button. Will open the .exe file
associated with selected item"""
User_Selected_exe_file = self._LotCombo.get()
os.startfile(User_Selected_exe_file)
def main():
Parking_Gui().mainloop()
main()