Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_pyinstaller2exe.py
- import sys
- import tkinter as tk
- from tkinter import messagebox
- from tkinter import filedialog
- import subprocess
- def convert_to_executable():
- script_path = filedialog.askopenfilename(title="Select Script", filetypes=[("Python Script", "*.py")])
- if script_path:
- args = []
- if use_console.get():
- args.extend(['-F', '-w'])
- else:
- args.extend(['-F', '-w', '--noconsole'])
- if use_name.get():
- args.extend(['-n', entry_name.get()])
- if use_icon.get():
- args.extend(['-i', entry_icon.get()])
- if use_add_data.get():
- args.extend(['--add-data', entry_add_data.get()])
- args.extend(['--add-binary', entry_add_data.get()])
- cmd = f"pyinstaller {' '.join(args)} {script_path}"
- process = subprocess.Popen(cmd, shell=True)
- process.wait()
- else:
- messagebox.showwarning("Error", "Please select a Python script to convert.")
- window = tk.Tk()
- window.title("Py To Exe")
- window.geometry("300x300")
- label = tk.Label(window, text="To Create An Executable\nFrom Python Scripted", font='bold')
- label.pack()
- use_console = tk.IntVar()
- console = tk.Checkbutton(window, text="Include Console", variable=use_console)
- console.pack()
- frame = tk.LabelFrame(window, text="Additional Options")
- frame.pack(ipadx=5, ipady=5)
- use_name = tk.IntVar()
- chk_name = tk.Checkbutton(frame, text="Specify Name:", variable=use_name)
- chk_name.pack()
- entry_name = tk.Entry(frame, width=40)
- entry_name.pack()
- use_icon = tk.IntVar()
- chk_icon = tk.Checkbutton(frame, text="Specify Icon Path:", variable=use_icon)
- chk_icon.pack()
- entry_icon = tk.Entry(frame, width=40)
- entry_icon.pack()
- use_add_data = tk.IntVar()
- chk_add_data = tk.Checkbutton(frame, text="Add Data File/Folder:", variable=use_add_data)
- chk_add_data.pack()
- entry_add_data = tk.Entry(frame, width=40)
- entry_add_data.pack()
- convert_button = tk.Button(window, text="Create The Executable", bg='lime', command=convert_to_executable)
- convert_button.pack(pady=5)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement