Home > Net >  How to work on same tkinter window from different python file?
How to work on same tkinter window from different python file?

Time:07-17

For example if I have a main.py file which has a root = tk.Tk() line for main window of GUI.
And another file menu.py which I want to use to add menu bar to the root window in main.py.

CodePudding user response:

This is actually really easy so don't worry.

First ensure that main.py and menu.py are in the same folder,

then at the beginning of main.py add from menu import *.

This should import all the data and python code from the other file so you can work in that file as if you were working in the main one.

CodePudding user response:

One way to achieve this is to just import main.py into menu.py.

Put this at the top of your menu.py code:

from main import *

now you will be able to access everything from main.py.

so you could do:

root.title("new title from menu.py")
  • Related