Main.py
import sys
import os
import subprocess
from subprocess import call
from tkinter import Tk, Button
def open_next_script():
if getattr(sys, 'frozen', False):
# Running as compiled executable
base_path = os.path.dirname(sys.executable)
else:
# Running as Python script
base_path = os.path.dirname(os.path.abspath(__file__))
script_path = os.path.join(base_path, 'next_file.py')
try:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.Popen([sys.executable, script_path], startupinfo=startupinfo)
except FileNotFoundError as e:
print(f"File not found: {e}")
except Exception as e:
print(f"Error occurred: {e}")
root.withdraw()
root = Tk()
# Create a button
button = Button(root, text="Open next.py", command=open_next_script)
button.pack()
# Start the main event loop
root.mainloop()
Next.py
from tkinter import Tk, Button
`your text`
print("Hello")
root = Tk()
root.mainloop()
Main.py and Next.py are not converted in one exe and are ready to use this exe in another computer to execute in only exe.