Detecting screen resolution using Tkinter

Arild Hansen arildh at stud.cs.uit.no
Wed Nov 8 16:03:56 EST 2000


"Alexander Schliep" <schliep at Octopussy.MI.Uni-Koeln.DE> wrote in message
news:<tq9k8aeslhd.fsf at Octopussy.MI.Uni-Koeln.DE>...

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

>

> > I have made a GUI application under Linux RedHat 7.0, python 2.0c1 using

> > Tkinter. The GUI looks extremely cool (!!) when I use a resolution 1024

> > * 768, but when I run the GUI in other resolutions the GUI sucks. So, I

>

> This seems to suggest that you did not use the layout managers (pack,

> grid) which would take care of that problem and, in case your windows

> are resizable, resizing of windows? Probably users choosing different

> fonts for the application will also cause problems.

>

> > would like to have the application detect the current screen resolution

> > and therefore adapt itself to this. My question is: How do I detect the

> > screen resolution in python? Thx for all help,

>

> If self is a Frame then self.master.winfo_screenwidth() and

> self.master.winfo_screenheight() give you the screen size,

> but I would use grid or pack.

>

> Yours,

> Alexander



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.

Arild Hansen









More information about the Python-list mailing list