Jun-25-2019, 03:43 PM
here's an example of a main window with multiple toplevel windows the pink window is tied with the main and will not close until the main closes the red and blue are independent:
from tkinter import Frame,Canvas,Button,Tk,Toplevel,Label class MainWindowExample(Frame): def __init__(self, parent= None): self.parent= parent Frame.__init__(self, self.parent) self.pack(expand='yes', fill='both') self.canvas= Canvas(self) self.canvas.config(width=500,height=300, bg='gray80') self.canvas.pack(expand='yes', fill='both') self.make_components() def make_components(self): self.label_1= Label(self.canvas, text='button One') self.label_1.place(x=10,y=10) self.button_1= Button(self.canvas, text='popup2', command=self.popup_2) self.button_1.place(x=100,y=10) self.myToplevel= Toplevel(width=200,height=250,bg='red')#seperate window self.myToplevel.title('example') self.myTopLevel_2= Toplevel(width=200,height=250,bg='pink') #closes w/main self.myTopLevel_2.protocol('WM_DELETE_WINDOW', lambda:None) def popup_2(self): self.toplevel= Toplevel(width=200,height=250,bg='blue') self.toplevel.title('example2') if __name__ == '__main__': root= Tk() MainWindowExample(root) root.mainloop()This can also be done other ways....