Tkinter have code for pages in separate files

The error messages tell you everything you need to know in order to fix the problem. This is a simple problem that has nothing to do with tkinter, and everything to do with properly organizing and using your code.

For example, what is Page is not defined telling you? It’s telling you, quite literally, that Page is not defined. You defined it in your main file, but you’re using it in another file. The solution is to move the definition of Page to a separate file that can be imported into the files that use it.

Modify your files and imports to look like this:

page.py

class Page(tk.Frame):
    ...

pageOne.py

from page import Page
class PageOne(Page):
    ...

pageTwo.py

from page import Page
class PageTwo(Page):
    ...

pageThree.py

from page import Page
class PageThree(Page):
    ...

Dashboard.py

from pageOne import PageOne
from pageTwo import PageTwo
from pageThree import PageThree
...

Leave a Comment