Search code examples
python-2.7pygtkgtk3

Discerning class parameters in documentation/class reference


Having some trouble reading the documentation for GTK+ 3. I've looked up and down for multiple class references that might clue me in. The one reference that I found that explicitly states the parameters passed when instantiating a class is outdated and missing several classes. The other 3 or 4 are laid out in a way that does not seem to explicitly state which parameters I need to pass.

The most complete class reference I've found is here. Using "Button" as an example, it gives a list of properties, including label, relief, xalign, yalign, etc. Yet, it does not identify which I need to pass when instantiating.

This isn't specific to this documentation library, but it's the one causing me grief right now. Where do I need to look to find this information?

Edit: More specifically, I'm looking for the kwargs, as well as how the control class processes them. In the button example, inputting a string as an argument sets the label. However, I cannot find why this is the case in the documentation.


Solution

  • Using GObject-based libraries from Python, you can rely on the following two rules of thumb for constructor arguments:

    1. Using positional arguments in constructors is deprecated.
    2. Keyword args correspond to writable properties.

    So, for example for Gtk.Button, here is where you'd find the allowed kwargs. Any property that has "w" (for "writable") listed under "Flags" can be set as a keyword arg when constructing the object.

    As for your question about where to find info about the positional args: they're deprecated, and so not present in the modern API documentation. You can go back to the old PyGTK API reference to see what's being emulated for compatibility, but I don't recommend writing any new code with positional constructor arguments.

    Just use

    button = Gtk.Button(label='Some text')