0

I am currently working on making a program using tkinter that when pressing a button it opens the Python program, however I am having some problems with it. I have tried using os.system('filename.py'). That opens the file, but then crashes the GUI, making the user have to restart the GUI. I have also tried importing it as a module but that just does the same as when using os.system.

Can anyone possibly help me open a Python file in a completely new window/terminal?

martineau
  • 119,623
  • 25
  • 170
  • 301
User592
  • 5
  • 5
  • What do you mean with "crashes the gui"? Could you elaborate on that? – tobspr Apr 23 '16 at 16:03
  • The GUI would stop responding but the code to the program that was being opened would go in to the terminal that was running the GUI – User592 Apr 23 '16 at 16:05
  • 1
    The GUI stops responding because `os.system()` waits for the _command_ given to complete before returning which temporarily prevents `tkinter`'s `mainloop` from processing any GUI events. You should use `subprocess.Popen` to run another Python script concurrently with the GUI. – martineau Apr 23 '16 at 17:14
  • 2
    [How do you run your own code alongside Tkinter's event loop?](http://stackoverflow.com/questions/459083/how-do-you-run-your-own-code-alongside-tkinters-event-loop) – Tadhg McDonald-Jensen Apr 23 '16 at 17:45

1 Answers1

0

The problem is filename.py will not be recognised by your os. Instead of that use:

os.system('python filename.py')

This will successfully open your python file inside your GUI Hope this helps

Johny Jose
  • 11
  • 4