How to determine the size and location Items or widget inside the window gtk python

How to determine the size and location Items or widget inside the window

I am using a plain ruler, but for more precision you may use a caliper. Another way is to make a photo of your screen, print it, then scan it in, load into a CAD program and use the CAD tools set for measurement.

:slight_smile:

Hello, and welcome!

There are a few questions that would help framing the context:

  1. what are you trying to achieve?
  2. Is it for debugging your own code?
  3. Are you trying to get this data programmatically?
  4. Which version of GTK are you using?

1-I want to create a window And it contains elements like button and Label

But the problem is here he is in Layout

I want to distribute the items I need four things

Locating the item x and y

Determine the size of the element height and width

GTK+3

That’s not how GTK layout works.

GTK layout managers do not require you to set the position and size of UI elements: they work by nesting boxes and defining whether a UI element should expand or not—and in case of expansion, what the UI element should do with the additional space at its disposal.

For instance, if you want to put a label next to a button, you can use a GtkBox widget, and add a GtkLabel and a GtkButton; then you can decide whether the label or the button should expand if the box is given more space than the minimum size its children require.

You should install the gtk3-demo demo application, which contains examples on various widgets and layout managers provided by GTK.

1 Like

I understand you beautiful But is there a way to use absolute mode ?

There’s GtkFixed and GtkLayout, but you are strongly discouraged to use them for actual UIs, as the fixed layout management does not recompute the sizing and position in case the user language (including the direction of the text) changes, or if the font size changes. You should only use GtkFixed and GtkLayout if you already know the size of everything, and you know that the UI won’t change.

Do not fight the toolkit: you will lose.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.