Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i create a window in a specific location

Status
Not open for further replies.

liquidshadow

Technical User
Dec 28, 2002
1
IL
I have a game i built which use the . window as a main
windows, but while the game i am opening a new windows
with toplevel.
I want to place this window not as default does (on the same . windows) but near my . window
How do i do it with a simple functions ?
 
You need to use 'wm geometry' that lets you fix the width, the height of the topleval and/or its x & y coordinates.

wm geometry .top +100+50
will place the .top window at 100,50.

From the Tk Manual:
wm geometry window ?newGeometry?
If newGeometry is specified, then the geometry of window is changed and an empty string is returned. Otherwise the current geometry for window is returned (this is the most recent geometry specified either by manual resizing or in a wm geometry command). NewGeometry has the form =widthxheight±x± y, where any of =, widthxheight, or ±x±y may be omitted. Width and height are positive integers specifying the desired dimensions of window. If window is gridded (see GRIDDED GEOMETRY MANAGEMENT below) then the dimensions are specified in grid units; otherwise they are specified in pixel units. X and y specify the desired location of window on the screen, in pixels. If x is preceded by +, it specifies the number of pixels between the left edge of the screen and the left edge of window's border; if preceded by - then x specifies the number of pixels between the right edge of the screen and the right edge of window's border. If y is preceded by + then it specifies the number of pixels between the top of the screen and the top of window's border; if y is preceded by - then it specifies the number of pixels between the bottom of window's border and the bottom of the screen. If newGeometry is specified as an empty string then any existing user-specified geometry for window is cancelled, and the window will revert to the size requested internally by its widgets.

For the complete description of the wm command:
HTH

ulis
 
The command you need is wm geometry. Check the wm reference page for complete information (for example, But basically, specifying only a window name returns the current size and position of the window in standard X style:

[tt]% wm geometry .
200x200+20+173[/tt]

In other words, my toplevel "." is 200x200 pixels in size (widthxheight), and located at X=20, Y=173 (in pixels) on my display (+x+y). A quick way to split this information out into separate variables is the Tcl split command:

[tt]% [ignore]foreach {width height x y} [split [wm geometry .] "x+"] {break}[/ignore]
% puts "Width: $width\nHeight: $height\nX: $x\nY: $y"
Width: 200
Height: 200
X: 20
Y: 173[/tt]

Providing a geometry specification to the wm geometry command requests the window manager to size and position the window accordingly. For example:

[tt]% toplevel .dialog
.dialog
% wm geometry .dialog 150x100+240+173[/tt] - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top