tkinter - Screen Resolution

Eric Brunel eric.brunel at pragmadev.com
Thu May 10 03:29:33 EDT 2007


On Wed, 09 May 2007 18:37:32 +0200, <rahulnag22 at yahoo.com> wrote:

> Hi,
> I have developed a GUI using tkinter (grid geometory manager).
> The structure is a top frame containing multiple subframes. Each
> subframe has a combination of widgets like(Entry, label,
> button,listboxes). The subframes are placed with a padx and pady
> offset with regards to the other subframes. And the widgets within
> these subframes have their own padx and pady offsets. The GUI runs
> fine on my linux box, but on a different linux box things get wierd.
> I see things like-
> 1) The frame width increasing
> 2) The widget padx translating to much bigger offsets with reference
> to the subframe edges
> 3) Widget widths like that for Entry become bigger
>
> I Know its to do with the screen resolution settings and user settings
> on different machines. Can anyone point me in the right
> direction(before I start looking into it)as how to account for
> different screen resolutions so as to have as uniform a GUI look as
> possible across different user machines.
[snip]

For some reason, tk uses different default units for coordinates and font  
sizes: a coordinate specified as just a number is considered to be in  
pixels (a.k.a screen points); a font size specified as just a number is  
considered to be in points, i.e 1/72 inch. So these units are the same  
only if your screen resolution is exactly 72 dpi, which is usually not the  
case.

If this is actually your problem, the way to correct it is quite simple:  
the tk command "tk scaling 1" tells tk that a point and a pixel are the  
same thing. To issue it, you may have to use explicitely the tcl  
interpreter used by Tkinter by doing:
aWidget.tk.call('tk', 'scaling', 1)
where aWidget is any Tkinter widget. This is what I had to do with Python  
2.1; it may be easier with later Python/Tkinter versions.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"



More information about the Python-list mailing list