Open Another Tkinter Program From A Main File
I have try this in my main program from tkinter import * import tkinter.filedialog import os root = Tk() def open(): PathPy = tkinter.filedialog.askopenfilename(title='Open a f
Solution 1:
Two additions to your code may give the expected result.
os.system expects a "command" for the operating system:
Execute the command (a string) in a subshell.
like python3 myscript.py
.
However, since you are using a custom python programming environment, pass the path of the EduPython's python.exe
to os.system
:
from tkinter import *
import tkinter.filedialog
import os
import sys
root = Tk()
pyexec = sys.executable
defopen():
PathPy = tkinter.filedialog.askopenfilename(title="Open a file",filetypes=[('PYTHON file','.py')])
os.system('%s %s' % (pyexec, PathPy))
B = Button(root, text="Open a file", command=open).pack()
root.mainloop()
Second, add the last line root2.mainloop()
to your second script to make the second Tk window appear.
Hope this helps.
Solution 2:
As you are trying to execute a python file, use execfile(file)
. But if all you want is a dialog, then use the Toplevel
class.
To keep both windows running, use different threads. It's very easy to do in python.
Post a Comment for "Open Another Tkinter Program From A Main File"