Tk – Windows Manager

  • Post author:
  • Post category:Tk
  • Post comments:1 Comment
Tk - Windows Manager

Tk Windows manager is used to handle the top level window. It helps in controlling the size, position, and other attributes of the window. It is used to refer the main window. The syntax for Tk windows manager command is shown below −

wm option window arguments

The list of options available for Tk wm command is shown in the following table −

Sr.No.Syntax & Description
1aspect windowName a b c dTries to maintain the ratio of width/height to be between a/b and c/d.
2geometry windowName geometryParamsUse to set geometry for window.
3grid windowName w h dx dySets the grid size.
4group windowName leaderNameleaderName gives the leader of a group of related windows.
5deiconify windowNameBrings the screen to normal if minimized.
6iconify windowNameMinimizes the window.
7state windowNameReturns the current state of window.
8withdraw windowNameUnmaps the window and removes its details in memory.
9iconbitmap windowName imageSets or returns the icon bitmap.
10iconPhoto windowName imageSets or returns the icon photo.
11command windowName commandStringRecords the startup command in the WM_COMMAND property.
12protocol windowName argumentsRegister a command to handle the protocol request name, which can be WM_DELETE_WINDOW,WM_SAVE_YOURSELF,WM_TAKE_FOCUS. Eg: wm protocol.WM_DELETE_WINDOW Quit.
13minsize windowName sizeDetermines the minimum window size.
14maxsize windowName sizeDetermines the maximum window size.
15title windowName titleTextDetermines the title for window.
16attributes subOptionsThere are lots of attributes available like alpha, full screen and so on.

Some of the above commands are used in the following example −

#!/usr/bin/wish

wm maxsize . 800 800
wm minsize . 300 300
wm title . "Hello"
wm attributes . -alpha ".90" 
wm geometry . 300x200+100+100

When we run the above program, we will get the following output −

As you can see alpha is one of the attributes available. The list of commonly used subcommands are listed below −

Sr.No.Syntax & Description
1-alpha numberSets the alpha for window.
2-fullscreen numberNumber can be 0 for normal screen or 1 for full screen.
3-topmost numberSets or returns whether window is topmost.Value can be 0 or 1.

Creating Window

We can use toplevel command to create window and an example is shown below −

#!/usr/bin/wish

toplevel .t

When we run the above program, we will get the following output −

Destroying Window

We can use destroy command to destroy window and an example is shown below −

#!/usr/bin/wish

destroy .t

The above command will destroy window named .t.

Next Topic : Click Here

This Post Has One Comment

Leave a Reply