1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
#
try:
import Tkinter as Tk
except:
import tkinter as Tk
class montoplevel(Tk.Toplevel):
def __init__(self, parent, txt):
Tk.Toplevel.__init__(self, parent)
self.parent = parent
Tk.Label(self, text=txt).pack()
def Quit(self):
self.destroy()
class appli(Tk.Tk):
def __init__(self, parent):
Tk.Tk.__init__(self, parent)
self.parent = parent
self.protocol("WM_DELETE_WINDOW", self.Intercepte)
self.tplist = []
for i in range(10):
self.tplist.append(montoplevel(self, 'Toplevel '+str(i)))
Tk.Button(self, text='Détruire '+str(i), command=self.tplist[i].Quit).pack()
def Intercepte(self):
#for elem in self.tplist:
# elem.destroy()
for widget in self.winfo_children():
if isinstance(widget, Tk.Toplevel):
widget.destroy()
self.quit()
if __name__ == "__main__":
app = appli(None)
app.title('Test Tkinter')
app.mainloop() |