General method of Tkinter (21) components

Time:2021-1-28
method explain
after(delay_ms, callback=None, *args) At least delay_ Ms after calling callback, no callback, equivalent time.sleep (); returns an ID to cancel after_ The cancel () method uses
after_cancel(id) Cancel the callback of after method call
after_idle(func, *args) Similar to the after method, but called when there is no event idle
bell() A beep
bind(sequence=None, func=None, add=None) Bind the callback function according to the event, add ‘+’ is the add function, and none will replace all the original functions
bind_all(sequence=None, func=None, add=None) Bind all parts, just like bind method
bind_class(className, sequence=None, func=None, add=None) Bind all the parts of the class name, just like the bind method
bindtags(tagList=None) Returns a list of label strings bound to events. The binding labels are window names or class aliases. Parameters can be used to specify the binding order
cget(option) Returns the string value of the part option. You can also use the widget [option]
clipboard_append(text) Paste text to scrapbook
clipboard_clear() Empty Scrapbook
columnconfigure(N, option=value, …) Set the column n option. The options are

Minsize – the minimum size of a dot element, which will not be displayed even if there is no part

Pad – provides extra spacing for the largest grid

Weight – extends the grid for more space, in quarter sizes
config(option=value, …) The same as the configure() method
configure(option=value, …) You can also use the widget [option] to set the option values of the component. The dictionary value of each option parameter will be returned without parameters. The key name of the dictionary is the name of each option, including the alias used. The way of key value is 5-tuple of option standard name (option standard name, option database key name, option database category, default value, existing value), or 2-tuple of option alias (option alias, Option (standard name)
destroy() Delete the part and all its subassemblies
event_add(virtual, *sequences) Add a virtual event named virtual string value. The sequence is a string of actual events. Any actual event will trigger the virtual event
event_delete(virtual, *sequences) In a virtual event named virtual string value, deleting a sequence will raise a string of actual events of the virtual event
event_generate(sequence, **kw) An event is generated, and the related field value is represented by * * kW
event_info(virtual=None) Returns a list of all defined virtual event names, or all the actual event names corresponding to a specific virtual event name. If not, returns none
focus_displayof() Returns the name of the focused window, otherwise none
focus_force() Set the focus on the part
focus_get() Return to the focused part, none if not
focus_lastfor() The name of the last focused part in the top-level window to which the part belongs. If there is no focus in the application, the top-level window name will be returned. If there is no focus in the application, the part name that will be focused next time will be returned
focus_set() If focus is applied, set focus on the part; otherwise, focus on the part the next time focus is applied
grab_current() If there is a grab in force for w’s display, return its identifier, otherwise return None
grab_release() If w has a grab in force, release it
grab_set() The component grabs all events in the application. If there are other forced grabs, they will disappear
grab_set_global() The component grabs all events on the full screen globally, and other grabs disappear
grab_status() If local crawling is enforced, “local” is returned; if global crawling is being performed, “global” is returned; if there is no valid crawling, none is returned
grid_forget() Hide the part, but its original grid option will be lost, and grid () will show the part again
grid_propagate(arg) If arg is set to 1, 0 will not be extended
grid_remove() The component is hidden, but its original grid option remains, and grid () displays the component again
image_names() Returns a string list of all picture names in the application
keys() Returns a string list of all selected item names of the part
lift(aboveThis=None) Move a window up to the topmost level or one level above a window
lower(belowThis=None) Move a window down to the bottom or the next level of a window
mainloop() The event processing loop is called after the creation of static components, or is invoked in the event to return to the event processing loop. The call quit () method ends.
nametowidget(name) Returns the part according to its pathname name name. If name does not exist, keyerror will be caused
option_add(pattern, value, priority=None) Add the default value to the options database. The string pattern represents the default value of the options

20 – Part universal intrinsic attribute

40 – application specific pre valued properties

60 – properties from user settings file

80 – attributes set at the beginning of the application (default priority)
option_clear() Cancel all option settings and restore all options to preset values
option_get(name, classname) Return the most suitable option value of classname, and return an empty string if none
option_readfile(fileName, priority=None) Use the option setting file to set the option value. The format is. Xdefaults. If the file is wrong, it will cause error tk.TclError
register(function) Returns the wrapper name string and changes function into a TCL wrapper
quit() End main loop
rowconfigure(N, option=value, …) Set the row n option. The options are

Minsize – the minimum size of a dot element, which will not be displayed even if there is no part

Pad – provides extra spacing for the largest grid

Weight – extends the grid for more space, in quarter sizes
selection_clear() Remove selection
selection_get() Returns the selected text. If there is no selection, the tk.TclError
selection_own() In addition, set the selection on the screen to all parts
selection_own_get() Return to the screen to select the part owned by. If there is no selection, select the part owned by tk.TclError
tk_focusFollowsMo​​use() According to the mouse position dynamic setting focus, can not simply cancel the action
tk_focusNext() Returns to the next focused part
tk_focusPrev() Return to the previous focused part
unbind(sequence, funcid=None) Remove the original binding of an event
unbind_all(sequence) Remove all the original binding of the event
unbind_class(className, sequence) Remove a class of parts, and all the original binding of its events will be removed
update() Update screen should not be invoked in callback of event.
update_idletasks() After the end of event processing, it returns to what it did before the event waiting loop. The main content is to update the screen / component
wait_variable(v) The variables of the local waiting part are set and will not block the running of the application
wait_visibility(w) Wait until part W is visible
wait_window(w) Wait until window W is closed
winfo_children() Returns the list of the bottom and top-level subcomponents
winfo_class() Returns the class alias of the part
winfo_containing(rootX, rootY, displayof=0) Returns the window relative to the application root window (displayof = 0) or the part top-level window (displayof = true) coordinates (rootx, Rooty). If it is not in the top-level window, returns none
winfo_depth() Returns the number of bits representing the pixel
winfo_fpixels(number) The pixel value of the size converted to floating point number
winfo_geometry() Return the location and size of the part. In the update_ The value will not be correct until the idletasks() method is used
winfo_height() Returns the current height of the part
winfo_id() Returns the integer identifier of the part in its top-level window
winfo_ismapped() True if the part has been configured in the top-level window and its parent parts have also been configured
winfo_manager() Returns the name of the component configuration manager, ‘grid’ /’pack ‘/’place’ /’canvas’ /’text ‘, otherwise it is an empty string
winfo_name() Returns the part name relative to the parent part
winfo_parent() Returns the pathname of the parent part, or an empty string if it is a top-level window
winfo_pathname(id, displayof=0) Return the part window path name with ID code in the application main window (displayof = 0) or top-level window (displayof = true)
winfo_pixels(number) The pixel value of the size converted to an integer
winfo_pointerx() Returns the X coordinate of the mouse coordinate relative to the root part. If it is not on the same screen, returns – 1
winfo_pointerxy() Returns the (x, y) coordinates of the mouse coordinates relative to the root part. If not on the same screen, returns (- 1, – 1)
winfo_pointery() Returns the X coordinate of the mouse coordinate relative to the root part. If it is not on the same screen, returns – 1
winfo_reqheight() Return the required height of the part to maintain the forming of the part
winfo_reqwidth() Return the required flatness of the part to maintain the forming of the part
winfo_rgb(color) Return (R, G, b) of color string, RGB value is [0, 65535]
winfo_rootx() Returns the X coordinate of the left side of the root window of the part and the outer edge of the outer frame relative to the parent part
winfo_rooty() Returns the Y coordinate of the outer edge of the outer frame above the root window of the part relative to the parent part
winfo_screenheight() Returns the height of the screen
winfo_screenmmheight() Returns the height of the screen in millimeters
winfo_screenmmwidth() Returns the screen’s resolution in millimeters
winfo_screenvisual() Return the string of screen color generation method, ‘TRUECOLOR’ (16 / 24 bit color),’pseudocolor ‘(256 color)
winfo_screenwidth() Returns the pixel of the screen
winfo_toplevel() Returns the top-level window of the part
winfo_viewable() Is the component visible
winfo_width() Returns the current dimension of the part
winfo_x() Returns the X coordinate of the left side of the part, the outer edge of the outer frame, relative to the parent part
winfo_y() Returns the Y coordinate of the upper part of the part, the outer edge of the outer frame, relative to the parent part

Sample windows and codes (omitted)

This work adoptsCC agreementReprint must indicate the author and the link of this article


Jason Yang