I can't figure out how to call a function from a tkinter Frame. I'm trying to implement a method that would protect the information from the App in case it's closed unintentionally. Could someone please help ?
from tkinter import Tk, Frame, Label
class MyApp(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
container = Frame(self)
container.pack(side="top", fill="both", expand = True)
frame = StartPage(container, self)
frame.grid(row=0, column=0, sticky='nsew')
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self,parent)
Label(self, text="close this window from the X in the corner").grid(row=1,column=1)
def Stop(self):
print('exiting')
app = MyApp()
if __name__=='__main__':
try:
app.mainloop()
finally:
OpenApp = MyApp()
OpenClass = StartPage(parent, OpenApp)
OpenClass.Stop()
I can't call the "Stop" function when closing tkinter. I get a NameError: name 'parent' is not defined. What should I put instead of "parent" ? If using the root.protocol("WM_DELETE_WINDOW", root.iconify) the function inside the class still has to be called.