I'm currently working on a tkinter project and the code is getting pretty long. What I would like to do is separate some of it into .py scripts and then import them into the main script. I'm not sure how to get a separate script to work like this. My example is a tkinter window that has many toplevel windows that have a lot of code in them. I'd like to keep those separate if possible. Something like this:
Instead of having all of the code from OtherScript in here, I'd like to import it and have it run after the root window button is clicked.
At the bottom of 'OtherScript.py ' I've added:
Code:
from Tkinter import * import OtherScript def NewWindow(): win = Toplevel() Run OtherScript.py root = Tk() root.geometry('300x300') Button(root, text='Click Me', command=NewWindow).pack(side=BOTTOM) mainloop()
At the bottom of 'OtherScript.py ' I've added:
Code:
if __name__ == "__main__": import sys
Comment