1 """ 2 programming pytyon page 422 3 pop up three new windows ,with style 4 desctory() kill one window,quit kill all windows and app 5 top-level window have litle,icon,iconify/deiconify and protocol for wn events 6 there always is an application root window,whether by default or created as an 7 explicit tk() object;all top-level windows are containters but they are never 8 packed.gridded;toplevel is like Frame,but a new window,and can have a menu; 9 """ 10 from Tkinter import * 11 root =Tk() 12 trees =[(‘the larch!‘,‘light blue‘),(‘the pine!‘,‘light green‘),(‘the giant redwood‘,‘red‘)] 13 14 for (tree,color) in trees: 15 win = Toplevel(root) 16 win.title(‘sing...‘) 17 win.protocol(‘WM_DELETE_WINDOW‘,lambda:None) #ignore close,so no meaning to close win by X 18 win.iconbitmap(‘C:\\Users\\xlian7164584\\Documents\\GitHub\\R_D\\bg.ico‘) 19 20 msg =Button(win,text=tree,command=win.destroy) 21 msg.pack(expand=YES,fill=BOTH) 22 msg.config(padx=10,pady=10,bd=10,relief=RAISED) 23 msg.config(bg=‘black‘,fg=color,font=(‘times‘,30,‘bold italic‘)) 24 root.title(‘lxk demo with three win‘) 25 Label(root,text=‘main win‘,width=30).pack() 26 Button(root,text=‘quit all‘,command=root.quit).pack() 27 root.mainloop()
原文:http://www.cnblogs.com/lxk613/p/4848223.html