[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

And finally, Figure 9-3 shows what happens after clicking the File menu’s tear-off line
and selecting the cascading submenu in the Edit pull down. Cascades can be nested as
deep as you like (though your users probably won’t be happy if this gets silly).


In tkinter, every top-level window can have a menu bar, including pop ups you create
with the Toplevel widget. Example 9-2 makes three pop-up windows with the same
menu bar as the one we just met; when run, it constructs the scene in Figure 9-4.


Figure 9-3. A File tear-off and Edit cascade


Figure 9-4. Multiple Toplevels with menus


Example 9-2. PP4E\Gui\Tour\menu_win-multi.py


from menu_win import makemenu # reuse menu maker function
from tkinter import *


root = Tk()
for i in range(3): # three pop-up windows with menus
win = Toplevel(root)
makemenu(win)


Menus | 511
Free download pdf