window manager is used to handle the top level window. it helps in controlling the size, position, and other attributes of the window. in tk, . is used to refer the main window. the syntax for window 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 |
|---|---|
| 1 |
aspect windowname a b c d tries to maintain the ratio of width/height to be between a/b and c/d. |
| 2 |
geometry windowname geometryparams use to set geometry for window. |
| 3 |
grid windowname w h dx dy sets the grid size. |
| 4 |
group windowname leadername leadername gives the leader of a group of related windows. |
| 5 |
deiconify windowname brings the screen to normal if minimized. |
| 6 |
iconify windowname minimizes the window. |
| 7 |
state windowname returns the current state of window. |
| 8 |
withdraw windowname unmaps the window and removes its details in memory. |
| 9 |
iconbitmap windowname image sets or returns the icon bitmap. |
| 10 |
iconphoto windowname image sets or returns the icon photo. |
| 11 |
command windowname commandstring records the startup command in the wm_command property. |
| 12 |
protocol windowname arguments register 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. |
| 13 |
minsize windowname size determines the minimum window size. |
| 14 |
maxsize windowname size determines the maximum window size. |
| 15 |
title windowname titletext determines the title for window. |
| 16 |
attributes suboptions there 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 number sets the alpha for window. |
| 2 |
-fullscreen number number can be 0 for normal screen or 1 for full screen. |
| 3 |
-topmost number sets 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.