[Python] What is the role of "master" in a tkinter widget?

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I've been working under the assumption that a widget's master is the geometric container of the widget. But recently I found that .place, .pack and .grid all accept an option in_ which allows you to position (that is, .place, .pack, or .grid, I'm using position in the sense of calling any of those methods) the widget inside a different container.

    The documentation uses master, parent, and container imprecisely. I used to think they all meant the same, but clearly that's not the case.


    • Something is passed - or left to default - as first argument to a widget's constructor. Let's call that something master. The master is defined at construction time and cannot ever be changed.


    • A widget is shown inside its container. The default container is the widget's master, but it can be any widget in the master-slave chain between the widget's master and the root because, when we (re)position a widget, an option in_ may be provided which (re)defines the widget's container. The container is defined after widget construction and can be changed by repositioning.

    I believe these statements to be true. But if that is so, if one can put a widget elsewhere than in its master, then what does the master do (other than provide a default container)? Could one leave the master unspecified in every widget (which would make root=Tk() the master of every widget) and simply use in_ to define their containers?

    Continue reading...

Compartilhe esta Página