Advertisement
here2share

# Tk_pyinstaller2exe.py

Nov 26th, 2023
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. # Tk_pyinstaller2exe.py
  2.  
  3. import sys
  4. import tkinter as tk
  5. from tkinter import messagebox
  6. from tkinter import filedialog
  7. import subprocess
  8.  
  9. def convert_to_executable():
  10.     script_path = filedialog.askopenfilename(title="Select Script", filetypes=[("Python Script", "*.py")])
  11.     if script_path:
  12.         args = []
  13.  
  14.         if use_console.get():
  15.             args.extend(['-F', '-w'])
  16.         else:
  17.             args.extend(['-F', '-w', '--noconsole'])
  18.  
  19.         if use_name.get():
  20.             args.extend(['-n', entry_name.get()])
  21.         if use_icon.get():
  22.             args.extend(['-i', entry_icon.get()])
  23.         if use_add_data.get():
  24.             args.extend(['--add-data', entry_add_data.get()])
  25.             args.extend(['--add-binary', entry_add_data.get()])
  26.  
  27.         cmd = f"pyinstaller {' '.join(args)} {script_path}"
  28.         process = subprocess.Popen(cmd, shell=True)
  29.         process.wait()
  30.     else:
  31.         messagebox.showwarning("Error", "Please select a Python script to convert.")
  32.  
  33. window = tk.Tk()
  34. window.title("Py To Exe")
  35. window.geometry("300x300")
  36.  
  37. label = tk.Label(window, text="To Create An Executable\nFrom Python Scripted", font='bold')
  38. label.pack()
  39.  
  40. use_console = tk.IntVar()
  41. console = tk.Checkbutton(window, text="Include Console", variable=use_console)
  42. console.pack()
  43.  
  44. frame = tk.LabelFrame(window, text="Additional Options")
  45. frame.pack(ipadx=5, ipady=5)
  46.  
  47. use_name = tk.IntVar()
  48. chk_name = tk.Checkbutton(frame, text="Specify Name:", variable=use_name)
  49. chk_name.pack()
  50.  
  51. entry_name = tk.Entry(frame, width=40)
  52. entry_name.pack()
  53.  
  54. use_icon = tk.IntVar()
  55. chk_icon = tk.Checkbutton(frame, text="Specify Icon Path:", variable=use_icon)
  56. chk_icon.pack()
  57.  
  58. entry_icon = tk.Entry(frame, width=40)
  59. entry_icon.pack()
  60.  
  61. use_add_data = tk.IntVar()
  62. chk_add_data = tk.Checkbutton(frame, text="Add Data File/Folder:", variable=use_add_data)
  63. chk_add_data.pack()
  64.  
  65. entry_add_data = tk.Entry(frame, width=40)
  66. entry_add_data.pack()
  67.  
  68. convert_button = tk.Button(window, text="Create The Executable", bg='lime', command=convert_to_executable)
  69. convert_button.pack(pady=5)
  70.  
  71. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement