0

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.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
  • thank you for the code, but would you like to explain what the problem is and what you are trying to achieve ? [how to ask](https://stackoverflow.com/help/how-to-ask) – D.L Jul 07 '23 at 08:39
  • Try looking at [How to make a tkinter button run another python file](https://stackoverflow.com/questions/58310718/how-to-make-a-tkinter-button-run-another-python-file). – Alias Cartellano Jul 07 '23 at 16:04

0 Answers0