Detecting screen resolution using Tkinter

Christian Tanzer tanzer at swing.co.at
Thu Nov 9 02:09:00 EST 2000


"Arild Hansen" <arildh at stud.cs.uit.no> wrote:

> Thx for answering. Actually (or should I say of course) I used pack and my
> GUI is fully rezisable. But, I have to led lights at the bottom of my GUI.
> These are created using canvas and create_rectangle and they are positioned
> using absolute coordinates according to their widget. One led is positioned
> to the left (i.e. coordinates 0,0 to 0+x, 0+y). This poses no problem since
> it always has the correct position no matter what resolution I use and no
> matter how much the user rezises the window. However, the second led is
> positionned to the right in my GUI and its absolute position (within the
> frame) is given by the coordinates b,0 and b+x, b+y). So when a user changes
> the size of the GUI the led does not move respectively to the first led.
> 
> So you see, all frames, widgets, menubars etc. behaves correctly (since I
> use pack), but it's the second led light (supposed to be to the right in my
> GUI) that doesn't "support" resizing. My question could therefore be
> reprhased as follows: how can I create a led light using the canvas and
> create_rectangle without having to draw the led using absolute coordinates
> but insted just define it's size and then "pack" it to the RIGHT? Hope
> someone can answer this question as I don't seem to figure it out myself.

Using `place' with the right combination of `x' and `relx' arguments
should to the trick. Instead of using one canvas with two rectangles,
you would use one frame containing two buttons or two canvases. Each of
these two would be positioned with place. For instance, 

   left.place  (relx = 0.0, x = +5)
   right.place (relx = 1.0, x = -5)

would place the left led 5 points from the left margin and the right
led 5 points from the right margin of the enclosing frame.

Of course, in this case `pack' would work just as well:

   left.pack  (side = LEFT,  ipadx = 5)
   right.pack (side = RIGHT, ipadx = 5)

`place' is handy if you want to position more than two elements.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list