I have a simple Tkinter GUI, with one button and when the button is pushed I want it to run another program that I have written in Python.
def openProgram ():
#open up MyProgram.py
MGui = Tk()
MGui.geometry('450x450')
mbutton = Button(text = "Go", command = openProgram).pack()
Seems easy enough, maybe I am not searching the correct terms.
asked Apr 23, 2014 at 19:16
eltel2910
3453 gold badges7 silver badges17 bronze badges
2 Answers 2
You can call functions defined in another file by importing that file.
reticulator.py:
def main():
print "reticulating splines..."
#do stuff here
print "splines reticulated"
gui.py:
from Tkinter import *
import reticulator
def openProgram():
#call the `main` function defined in the other file
reticulator.main()
MGui = Tk()
MGui.geometry('450x450')
mbutton = Button(text = "Go", command = openProgram).pack()
MGui.mainloop()
answered Apr 23, 2014 at 19:25
Kevin
76.5k13 gold badges141 silver badges168 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
scotty3785
This is a much better answer than the accepted one. Calling another python program using os.system shows a lack of understanding of modular programming.
Pedroski
I want to open a Python program in its own window. Will this do that?
Try to use os.system:
import os
os.system("MyProgram.py")
answered Apr 23, 2014 at 19:23
NorthCat
10k16 gold badges51 silver badges56 bronze badges
lang-py