Version 16 of Maximizing a toplevel window

Updated 2005-02-11 08:17:09

Maximizing a toplevel window: Customers sometimes want a window to come up maximized (they want it to be as though they had touched the fill-the-screen button in the window-manager's decoration).

      package require Tcl 8.2 ;# [package present] and [string equal]
      package require Tk
      proc maximize toplevel {
             # Unixoid window managers definitely can't rely on "wm ... zoom";
             #    can MacOS?
             # "wm state ..." only began to take "zoom" with version 8.3.
         if {([catch {package present Tk 8.3}] == 0) &&
              [string equal $::tcl_platform(platform) windows]} {
             wm state $toplevel zoomed
             return
         }
         pack propagate $toplevel 0
         update idletasks
         wm geometry $toplevel +0+0
         wm minsize $toplevel [winfo screenwidth $toplevel] \
                               [winfo screenheight $toplevel]
      } ;# [CL]

An alternative, to support Tcl/Tk versions older than 8.2 (at least 7.5/4.1):

      package require Tk
      proc maximize toplevel {
          global tcl_platform
              # [wm state] able to set state beginning with Tk 8.3.
              # "zoomed" state available only on Windows.
          if {![package vsatisfies [package provide Tk] 8.3]
              && ([string compare $tcl_platform(platform) windows] == 0)} {
              wm state $toplevel zoomed
              return
          }
          pack propagate $toplevel 0
          update idletasks
          wm geometry $toplevel +0+0
          wm minsize $toplevel [winfo screenwidth $toplevel] \
                               [winfo screenheight $toplevel]
      }

DGP


Someone who wants to pursue this for Win32 should examine http://user.cs.tu-berlin.de/~eserte/src/perl/Win32Util/


RS A one-liner that works on Windows 2000 (and should on others, too):

 wm overrideredirect . 1; wm geometry . [join [wm maxsize .] x]+0+0

Tkinter can do the same, of course [L1 ].


If you use the current version of Tk with Windows, this works:

    wm state . zoom

    wm state . zoomed  

RA2 But of course if you first have a line in your main.proc defining a smaller window, such as "wm geometry . +20+20" make sure you delete it for it will take precedence over your maximized window call (don't make the same mistake I did! :-).

But come to think of it, wouldn't it be normal that we don't mention anything, that the default should be a maximized window?

Incidently what do the 20 and 20 refer to here: "wm geometry . +20+20" ? Anyone has a clue? - RS: A good source for clues is the man page :^) "NewGeometry has the form =widthxheight±x±y, where any of =, widthxheight, or ±x±y may be omitted. (...) 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."


Opening the console maximized

RA2 Hi! I'd like to attach a console to my TCL program. What code do I enter, where and how to start a console maximized (100%)? Thanks I appreciate!

RS: See console and Maximizing a toplevel window, but here's what works for me on Win XP:

 % console show
 % console eval {wm state . zoomed}

RA2 Thanks so much Richard! You are very kind!


See Also:

A fullscreen toplevel