All this has to do with styling, as Matt noted. The stacking order is just the "z-coordinate" for widgets in your application. you can think of it as if, in addition to the natural x and y coordinates that you have on the screen, there is another axis perpendicular to the plane of the screen. All widgets are somewhere along this axis. The image you see on the screen is the result of "smoothing" all the widgets together along this axis. Anywhere where widgets overlap in the x and y plane, the widget that is higher in stacking order is what you see in that place.
By default, the storage order of widgets in Tk is determined by the order in which they are created. The earlier the widget that he created, the lower it is in the stacking order - think that the screen itself is at the z-coordinate z, while increasing values ββget closer to you from the screen. The first widget created has zero stacking order, the second one has one, etc.
The simplest solution to your problem is to simply create the widgets in the correct order, but if you are configured to create widgets in the specified order, you can manually change the stacking order later to make sure the widgets are stacked in the order you want. For example, to add your blue frame to the top again, you can add:
raise .top .root
This tells Tk to reorder the .top stacking so that it is βaboveβ .root .
When I use a window widget, I try to control child widgets - for me, this is conceptually only a frame with additional behavior, and since I use frames to group related widgets together, I use the window window in the same way. This policy also neatly wraps up the styling issue, since it requires you to open the window first - you must because you cannot create child elements of the widget until the widget itself is created. Thus, I would modify your example as follows:
panedwindow .root -orient vertical -showhandle true -background red frame .root.top -background blue -width 100 -height 100 frame .root.bot -background green -width 100 -height 100 .root add .root.top .root.bot
For me, this makes the connection between .root and .root.top and .root.bot clear: two frames are "inside" on the stack. The natural stacking order is correct and everyone is happy.