On 8/5/2014 7:33 PM, Nicholas Cannon wrote:
I am confused. When I did menu bar.add_cascade why don't I do filemenu.add_cascade. Is it because I am adding a cascade to the main menubar?
Let us start with a widget, that can 'contain' other widgets (and possibly other things). We create a child widget (which keeps a reference to the parent. Now we want to put it into the parent. How?
The generic grid, pack, and place geometry methods are called on the child, with no mention of the parent. (The child reference to the parent is used instead.) Do note, however, that child-independent geometry configure methods, like grid rowconfigure, are called on the parent.
Widget-specific geometry methods, however, are (mostly at least) called on the parent, with the child passed as a parameter. Menus can contain both commands, which are not widgets, and submenus, which are. They are packed with add_command and add_cascade. Canvases have add methods that place items, which again may or may not be widgets.
I initially found child.pack(args) confusing, because I expected the pattern to be (child.parent).pack(child, args). But now that I think about it, the shortcut is similar to instance.method(args) sometimes meaning (instance.__class__).method(instance, args). The convenience in both cases is about the same.
-- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list