Fish C Note--python GUI programming (15): Tkinter components TopLevel and methods of TK and TopLevel

Source: Internet
Author: User
Tags pack string format

The TopLevel (top-level window) component is similar to a frame component, but the TopLevel component is a stand-alone top-level window that usually has parts such as title bars, borders, and so on, and is the same as the root window created by TK (), sharing the same method.


When to use the TopLevel component.

TopLevel components are typically used to display additional windows, dialogs, or other pop-up windows.


In the following example, we add a button to the root window to create a top-level window and click one.

From Tkinter import *

root = Tk ()

def create (): Top
    = toplevel ()
    top.title (' Python ')

    msg = Message ( Top, text= ' I Love study ')
    msg.pack ()

Button (Root, text= ' create top-level window ', command=create). Pack ()

Mainloop ()




Tk (Root window) and toplevel (top-level window) methods:

This series of methods below is used to interact with the window manager. They can be invoked by the TK (Root window) and also apply to TopLevel (top-level windows).

Note: Not all operating systems fully support implementation of all methods below.


Aspect (Minnumber=none, Mindenom=none, Maxnumber=none, Maxdenom=none,)

--Control the width-height ratio of the window (width:height)

--width-height ratio limited in: minnumber/mindenom~maxnumber/maxdenom

--If the argument is omitted, a 4-tuple is returned to indicate the current limit (if any)


Attribute (*args)

--Set and get window properties

--If you only give the option name, it will return the value of the current Window option

-Note: The following options do not support keyword parameters, you need to Ga Gang (-) in front of the options and in a string format, separating the options and values with commas (,).

For example, if you want to set the window's transparency to 50%, you should use attribute ("-alpha", 0.5) instead of attribute (alpha=0.5)

--Below is a list of the specific meanings and usages of the various options that args can use:

Alpha: (WINDOWS,MAC) controls transparency of Windows

1.0 indicates opacity, 0.0 indicates full transparency

This option does not support all systems, and for unsupported systems, Tkinter draws an opaque (1.0) window

Disabled: (Windows) disables the entire window (you can only turn it off from Task Manager)

Fullscreen: (WINDOWS,MAC) If set to True, the window is displayed full screen

Modified: (MAC) If set to True, the window is marked as altered

Titlepath: (MAC) Setting the path of the window proxy icon

ToolWindow: (Windows) If set to true, the window takes the style of a tool window

Topmost: (WINDOWS,MAC) If set to true, the window will always be sticky


Client (Name=none)

--Set and get Wm_client_machine properties

--If you want to delete the Wm_client_machine property, the assignment is an empty string

--this property only supports the window Manager of the X Window System, and other systems ignore


Colormapwindows (*wlist)

--Set and get Wm_colormap_windows properties

--this property only supports the window Manager of the X Window System, and other systems ignore


Command (Value=none)

--Set and get WM_COMMAND properties

--this property only supports the window Manager of the X Window System, and other systems ignore


Deiconify ()

--Display window

--The newly created window is displayed on the screen by default, but the iconify () or withdraw () method allows you to remove the window from the screen


Focusmodel (Model=none)

--Set and get focus mode


FRAME ()

--Returns a string representing the current system characteristics

--for Unix-like systems, the return value is the X Window identifier

--For Windows systems, the return value is the result of the HWND cast to long shaping


Geometry (Geometry=none)

--Set and get the size of the window

The--geometry parameter format is: "%dx%d%+d%+d"% (width, height, xoffset, yoffset)


(wm_) grid (Basewidth=none, Baseheight=none, Widthinc=none, Heightinc=none)

--Notifies the window manager that the window will resize in the form of a grid

--basewidth and BaseHeight Specify the number of grid units required for Tk_geometryrequest

--widthinc and heightinc the height and width of the specified cell


(WM_) Group (Window=none)

--Add a window to the window group

--window parameter specifies the main window of the control window group

--If this option is omitted, the main window for the current window group is returned


(wm_) Iconbitmap (Bitmap=none, Default=none)

--Set and get the icon for the window

-For example Root.iconbitmap (bitmap= "Python.ico")

The--default parameter can be used to specify the default icon for a child window created by the window


(WM_) iconify ()

--Icon of the window (minimized)

--You need to display the window again, using the Deiconify () method

-This method causes state () to return to "iconic"


(wm_) Iconmask (Bitmap=none)

--Set and get bitmap encoding


(wm_) Iconname (Newname=none)

--Sets and gets the icon name when the current window is icon (minimized)


(wm_) iconposition (X=none, Y=none)

--Sets and gets the icon position when the current window is icon (minimized)


(wm_) Iconwindow (Pathname=none)

--Sets and gets the component window when the current window is icon (minimized)

This method will cause state () to return "icon"


(wm_) maxsize (Width=none, Height=none)

--Sets and gets the maximum size of the window


(wm_) MinSize (Width=none, Height=none)

--Sets and gets the minimum size of the window


(wm_) Overrideredirect (Boolean=none)

--If the argument is true, the window ignores all widgets (that is, the window will have no traditional title bars, borders, etc.)


(wm_) Positionfrom (Who=none)

--Specify window position by "who decides

--If the WHO parameter is "user", the window position is determined by the user

--If the WHO parameter is "program", the window position is determined by the system


(wm_) protocol (Name=none, Func=none)

--Bind the callback function func to the corresponding rule name

The--name parameter can be "Wm_delete_window": When the window is closed

The--name parameter can be "wm_save_yourself": When the window is saved

The--name parameter can be "Wm_take_focus": When the window gets the focus


(wm_) resizable (Width=none, Height=none)

--Specifies whether you can change the size of the window

--width is true to allow the horizontal size of the window to be resized

--height is true to allow the vertical dimensions of the window to be adjusted


(wm_) Sizefrom (Who=none)

--Specify window size by "who decides

--If the WHO parameter is "user", the window size is determined by the user

--If the WHO parameter is "program", the window size is determined by the system


(wm_) state (Newstate=none)

--Sets and gets the status of the current window

--newstate can only be ' normal ', ' Iconoc ' (see iconify), ' withdraw ' (see withdraw), ' icon ' (see Iconwindow) and ' zoomed ' (magnified, Windows-specific)


(wm_) title (String=none)

--Set the title of the window


(wm_) Transient (master=none)

--temporary window specified as Master


(WM_) Withdraw ()

--Remove the window from the screen (not destroyed)

--You need to display the window again, using the Deiconify () method

-This method causes state () to return to "withdraw"


Wm_aspect (Minnumber=none, Mindenom=none, Maxnumber=none, Mandenom=none)

--See above aspect ()


Wm_attributes (*args)

--See above attributes ()


Wm_client (Name=none)

-See above client ()


Wm_colormapwindows (*wlist)

--See above Colormapwindows ()


Wm_command (Value=none)

--See command above ()


Wm_deiconify ()

--See above Deiconify ()


Wm_focusmodel (Model=none)

--See above Focusmodel ()


Wm_frame ()

--See above frame ()


Wm_geometry (Geometry=none)

--See above geometry ()


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.