I want to create a screen manager in python. A menu with options for screens to go, and on each screen an option to go back to the menu. If I put the classes in the same file I won't have a problem, but if I try to modularize and distribute the classes in files, I can't import the 'main()' function in FirstScreen, for example. Each screen is in a different class and in a different file, when I try to go back to the menu the circle error will occur. What is the best way to solve it? Here is the code for each file:
Main
from tkinter import *
from primeira import *
class main():
def __init__(self):
self.master = Tk()
self.master.title('main window')
self.master.geometry('480x240')
self.master.configure(borderwidth=4, background='white')
self.button = Button(self.master, text='window one', command= lambda: self.evento())
self.button.pack(side='left', fill='x')
self.master.mainloop()
def evento(self):
self.master.destroy()
FirstWindow()
main()
First window (in another archive)
from tkinter import *
from main import main
class FirstWindow():
def __init__(self, master=None):
master = Tk()
self.master = master
self.master.title('window one')
self.master.configure(background='green')
self.master.geometry('480x240')
self.button = Button(master, text='menu', command= lambda: self.goMain())
self.button.pack(side='left', fill='x', expand=True)
master.mainloop()
def goMain(self):
self.master.destroy()
main()