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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I place my Tk-window always at the upper left? 1

Status
Not open for further replies.

BioDJ

Programmer
Oct 5, 2001
10
0
0
NL
Dear reader,
I have a question. I'm working on a simple text and numeric editor and for that I use a Tk window. When I close that window and start my program again the window is placed a little to the lower and right. This continues until one of the windows in a row reaches a certain point near the middle of the screen. Then the next window is placed at the upper left corner of the screen.

I have tried this: wm geometry . 20x50+0+0

I thought this would mean height-width-xcoordinate-ycoordinate. But the windows still keep following eachother up as they "walk" to the center and start again from the upper left corner.

I hope this is all clear and that someone has an idea. It would be very welcome.

Greets
Dirk-Jan (BioDJ)
 
On my PC, with Tcl 8.3, this works as you expect (always the same place).
What you describe is without the wm geometry command.

ulis
 
No I was talking about WITH the wm geometry command. Thanks anyway.

BioDJ
 
BioDJ: You're using the correct command to position (and size) a toplevel window. However, there's still the possibility that it won't work on your system. Here's why:

The window manager controls the size and position of all windows on your desktop. The window manager is part of the operating system on Windows and Macintosh systems, and a separate application on Unix systems (for example, gnome or KDE or mwm). An application can make requests of the window manager, but the window manager is free to ignore or modify those requests. The application can never force the window manager to do anything (because it would be a gaping security hole otherwise).

The wm command is how you send requests to the window manager from a Tcl application. Most well-behaved window managers grant geometry requests like you've made, but some window managers aren't well-behaved.

About the only suggestion I have for you is to try the following:

Code:
# Take the window offscreen temporarily

wm withdraw .

# Do all of your wm stuff here...

wm geometry . 20x50+0+0

# Put the window back onscreen

wm deiconify .

Some window managers won't make any programmatic changes to a toplevel window currently displayed. But if we take the window offscreen, make the changes, and then redisplay it, it works ok.

Good luck! - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
you could also try the "update" command. Sometimes the window manager lags the script in actual execution. Update forces it.
 
Thank you, Aviatraining. Your withdraw-deiconify suggestion works!

greets
biodj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top