Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I determine the screen size in Tk ?

860 views
Skip to first unread message

Mark Hobley

unread,
Oct 2, 2005, 1:08:03 AM10/2/05
to
I am new user of Tcl/Tk.

How do I determine the maximum size of canvas that I can use within my Tcl/Tk
application?

For example, if the screen is 640x480, I want to create a canvas size of just
below this. However, if the screen is 800x600, I would wish the canvas to be
larger.

On an 800x600 screen, I tried:

% canvas .canv -width 800 -height 600
% pack .canv

The resultant window was larger than the screen due to the border, and the
frame went below the taskbar on my window manager ?

Is there a way that I can determine the number of pixels to reduce the canvas
by ?

The window was positioned in such a manner that its left hand edge was across
the screen and needed to be moved with the mouse.

Is there a way to force it into the top left corner ?

If I was creating a frame less than full size, I would probably want it to
begin centrally on the screen.

How can I do this ?

Can this be done purely within tcl or tk ?

I would like a generic solution that suits all platforms, if possible, as
opposed to using conditional branching based upon the platform type.

Thanks in advance to anyone who can help.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

Heinz-Jürgen Oertel

unread,
Oct 2, 2005, 4:15:03 AM10/2/05
to
Mark Hobley wrote:

> I am new user of Tcl/Tk.
>
> How do I determine the maximum size of canvas that I can use within my
> Tcl/Tk application?
>
> For example, if the screen is 640x480, I want to create a canvas size of
> just below this. However, if the screen is 800x600, I would wish the
> canvas to be larger.
>
> On an 800x600 screen, I tried:
>
> % canvas .canv -width 800 -height 600
> % pack .canv
>
> The resultant window was larger than the screen due to the border, and the
> frame went below the taskbar on my window manager ?
>
> Is there a way that I can determine the number of pixels to reduce the
> canvas by ?
>

Look at the wm command.
"The wm command is used to interact with window managers in order to control
such things as the title for a window, its geometry, or the increments in
terms of which it may be resized."

wm maxsize
could be what you are looking for.


> The window was positioned in such a manner that its left hand edge was
> across the screen and needed to be moved with the mouse.
>
> Is there a way to force it into the top left corner ?
>

again, look for the wm command, something like

wm geometry $window 200x200+0+0
^^^^

> If I was creating a frame less than full size, I would probably want it to
> begin centrally on the screen.
>
> How can I do this ?
>
> Can this be done purely within tcl or tk ?
>
> I would like a generic solution that suits all platforms, if possible, as
> opposed to using conditional branching based upon the platform type.
>
> Thanks in advance to anyone who can help.
>
> Regards,
>
> Mark.
>

--

with best regards / mit freundlichen Grüßen

Heinz-Jürgen Oertel

+===================================================================

Merokok dapat menyebabkan kanker, serangan jantung,
impotensi dan gangguan kehamilan dan janin.

Bryan Oakley

unread,
Oct 2, 2005, 10:22:51 AM10/2/05
to
Heinz-Jürgen Oertel wrote:

> Mark Hobley wrote:
>>How do I determine the maximum size of canvas that I can use within my
>>Tcl/Tk application?
>
> Look at the wm command.
> "The wm command is used to interact with window managers in order to control
> such things as the title for a window, its geometry, or the increments in
> terms of which it may be resized."
>
> wm maxsize
> could be what you are looking for.

No, that not correct; please read the man page.

To get the screen size use the winfo command. There are commands to get
the screen width (winfo screenwidth) and height (winfo screenheight) as
well as other similar functions.

Heinz-Jürgen Oertel

unread,
Oct 2, 2005, 12:35:00 PM10/2/05
to
Bryan Oakley wrote:

Agreed, but at least the SEE ALSO section points to it :-)

SEE ALSO
toplevel(n), winfo(n)

Regards
Heinz

Arndt Roger Schneider

unread,
Oct 2, 2005, 1:20:53 PM10/2/05
to
Bryan Oakley schrieb:

> To get the screen size use the winfo command. There are commands to get
> the screen width (winfo screenwidth) and height (winfo screenheight) as
> well as other similar functions.

Yes -- also Tk doesn't update this coordinates ...


Using pivot software, such as ATI-Displays, to change the
orientation wont be reflected with screenwidth/height

winfo screenwidth . -> 1680
<rotate screen>

same width

-roger

Jeff Hobbs

unread,
Oct 2, 2005, 2:21:25 PM10/2/05
to Arndt Roger Schneider
Arndt Roger Schneider wrote:
> Yes -- also Tk doesn't update this coordinates ...
>
> Using pivot software, such as ATI-Displays, to change the
> orientation wont be reflected with screenwidth/height
>
> winfo screenwidth . -> 1680
> <rotate screen>
>
> same width

As of Tk 8.4.8, Tk should respond to the Windows display changed
message and recache the screen info (like resolution and/or
screen size changes).

--
Jeff Hobbs, The Tcl Guy
http://www.ActiveState.com/, a division of Sophos

0 new messages