I'm building a tkinter-window-maker and I'm having trouble with the 'new_window' method within the parent class. I can modify it slightly and copy paste it within each child class to where it works fine but it seems inefficient, if I put the method within the parent class however (code below) it hits the max recursion depth. What's wrong?
Code:
from tkinter import *
import sys
class Window():
def __init__(self, master, x, y, title):
self.master = master
master.title(title)
master.geometry("{}x{}".format(x,y))
def new_window(self, class_name):
self.master.destroy()
class_name = getattr(sys.modules[__name__], str(class_name))
root=Tk()
class_name(root)
root.mainloop()
class Login(Window):
def __init__(self, master):
super().__init__(master, 200, 200, "Login")
Button(master, text="NEXT",width=7,height=1,command=self.new_window("Home")).grid(row=1,column=1)
class Home(Window):
def __init__(self, master):
super().__init__(master, 200, 200, "Home")
Button(master, text="NEXT",width=7,height=1,command=self.new_window("Login")).grid(row=1,column=1)
def main():
root=Tk()
Login(root)
root.mainloop()
if __name__ == '__main__':
main()