Ich habe versucht, eine ausführbare Datei für eine tkinter
GUI zu erstellen, die ich in Python 2.7 erstellt habe. Bisher habe ich versucht mit py2exe
und pyinstaller
aber ohne Glück. Wenn ich py2exe
versuchte, würde die cmd
Pop-up und dann sofort schließen. Wenn ich pyinstaller
verwendet, würde die ausführbare Datei "kein Skript ausführen". Ich bin mir nicht sicher, was ich falsch mache. Hier ist das Skript, das ich für meine GUI geschrieben habeErstellen einer Exe für tkinter Python 2.7
import Tkinter as tk
from tkFileDialog import askopenfilename
from Tkinter import *
import pandas as pd
import ttk
import subprocess
# Import all graph codes.
import graph_1
import graph_2
import graph_3
import graph_4
def import_csv_data():
global v
csv_file_path = askopenfilename()
print(csv_file_path)
v.set(csv_file_path)
df = pd.read_csv(csv_file_path)
def openfile():
subprocess.call(['notepad.exe', 'C:/help.txt'])
# Functions for calling graphs.
def graph_1():
graph_1.display_graph(v.get())
def graph_2():
graph_2.display_graph(v.get())
def graph_3():
graph_3.display_graph(v.get())
def graph_4():
graph_4.display_graph(v.get())
# Read in data buttons.
root = tk.Tk()
tk.Label(root, text='File Path').grid(row=0, column=0)
v = tk.StringVar()
entry = ttk.Entry(root, textvariable=v).grid(row=0, column=1)
ttk.Button(root, text='Browse Data Set',command=import_csv_data).grid(row=1, column=0)
# Title and icon of the GUI.
root.title('Graphs')
root.iconbitmap('C:/icon.ico')
root.geometry("370x118")
#Graph Buttons.
ttk.Button(root, text='Graph 1', command=graph_1).grid(row=3, column=0)
ttk.Button(root, text='Graph 2', command=graph_2).grid(row=3, column=1)
ttk.Button(root, text='Graph 3', command=graph_3).grid(row=4, column=0)
ttk.Button(root, text='Graph 4', command=graph_4).grid(row=4, column=1)
def new_window():
# Import all graph codes.
import graph_1
import graph_2
import graph_3
import graph_4
def import_csv_data():
global v
csv_file_path = askopenfilename()
print(csv_file_path)
v.set(csv_file_path)
df = pd.read_csv(csv_file_path)
# Define the functions before calling them.
def doNothing():
print "nothing"
# Functions for calling graphs.
def graph_1():
graph_1.display_graph(v.get())
def graph_2():
graph_2.display_graph(v.get())
def graph_3():
graph_3.display_graph(v.get())
def graph_4():
graph_4.display_graph(v.get())
# Read in data buttons.
root = tk.Tk()
tk.Label(root, text='File Path').grid(row=0, column=0)
v = tk.StringVar()
entry = tk.Entry(root, textvariable=v).grid(row=0, column=1)
ttk.Button(root, text='Browse Data Set',command=import_csv_data).grid(row=1, column=0)
# Title and icon of the GUI.
root.title('Graphs')
root.iconbitmap('C:/icon.ico')
root.geometry("370x118")
#Graph Buttons.
ttk.Button(root, text='Graph 1', command=graph_1).grid(row=3, column=0)
ttk.Button(root, text='Graph 2', command=graph_2).grid(row=3, column=1)
ttk.Button(root, text='Graph 3', command=graph_3).grid(row=4, column=0)
ttk.Button(root, text='Graph 4', command=graph_4).grid(row=4, column=1)
#Menu setup and buttons for new window.
menu = Menu(root)
root.config(menu=menu)
subMenu = Menu(menu)
menu.add_cascade(label="File",menu=subMenu)
subMenu.add_command(label="New", command=new_window)
subMenu.add_command(label="Exit", command=root.destroy)
editMenu = Menu(menu)
menu.add_cascade(label = "Help", menu=editMenu)
editMenu.add_command(label="Help", command=openfile)
# Menu setup and buttons.
menu = Menu(root)
root.config(menu=menu)
subMenu = Menu(menu)
menu.add_cascade(label="File",menu=subMenu)
subMenu.add_command(label="New", command=new_window)
subMenu.add_command(label="Exit", command=root.destroy)
editMenu = Menu(menu)
menu.add_cascade(label = "Help", menu=editMenu)
editMenu.add_command(label="Help", command=openfile)
root.mainloop()
IME mit dem Erstellen Python ausführbare Dateien, der Schlüssel ist mit einem sehr minimalen Programm zu starten, und wenn Sie das zum Laufen bringen, allmählich Funktionen hinzufügen, bis Sie die eine finden, die das Problem verursacht. –