📜  Tk-Windows Manager

📅  最后修改于: 2020-10-16 06:36:23             🧑  作者: Mango


窗口管理器用于处理顶级窗口。它有助于控制窗口的大小,位置和其他属性。在Tk中。用于引用主窗口。 window命令的语法如下所示-

wm option window arguments

下表显示了Tk wm命令可用的选项列表-

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.

以下示例中使用了上述一些命令-

#!/usr/bin/wish

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

当我们运行上面的程序时,我们将获得以下输出-

窗口管理器

如您所见,alpha是可用的属性之一。下面列出了常用的子命令列表-

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.

创建窗口

我们可以使用toplevel命令创建窗口,示例如下所示-

#!/usr/bin/wish

toplevel .t

当我们运行上面的程序时,我们将获得以下输出-

窗口管理器2

破坏窗口

我们可以使用destroy命令销毁窗口,示例如下所示-

#!/usr/bin/wish

destroy .t

上面的命令将销毁名为.t的窗口。