Tkinter Window and Basic Widgets
Command | Description |
---|
Tk() | Creates the main window of the application. |
mainloop() | Starts the Tkinter event loop. |
title(string) | Sets the title of the window. |
geometry(string) | Sets the dimensions of the window. |
resizable(width, height) | Determines whether the window can be resized. |
Label(master, text="") | Creates a label widget. |
Button(master, text="", command=None) | Creates a button widget. |
Entry(master) | Creates a single-line text entry widget. |
Text(master) | Creates a multi-line text entry widget. |
Frame(master) | Creates a container for organizing widgets. |
Canvas(master) | Creates a canvas widget for drawing. |
Widget Configuration and Grid Management
Command | Description |
---|
pack() | Packs the widget into the window (default packing). |
grid(row, column) | Places the widget in a specific row and column in the grid layout. |
place(x, y) | Places the widget at an absolute position. |
config(option=value) | Configures widget options. |
bind(event, handler) | Binds an event to a handler function. |
columnconfigure(index, option=value) | Configures column options in a grid. |
rowconfigure(index, option=value) | Configures row options in a grid. |
Event Handling and Widget Methods
Command | Description |
---|
bind(event, handler) | Binds an event to a widget. |
unbind(event) | Unbinds an event from a widget. |
after(ms, callback) | Calls the callback after a specified time in milliseconds. |
after_cancel(id) | Cancels a scheduled callback. |
destroy() | Destroys a widget. |
focus() | Sets focus on a widget. |
grab_set() | Directs all events to this widget. |
grab_release() | Releases the grab on the widget. |
Common Widget Options
Option | Description |
---|
text | Sets the text displayed by the widget. |
bg or background | Sets the background color. |
fg or foreground | Sets the foreground (text) color. |
font | Sets the font type, size, and style. |
width | Sets the width of the widget. |
height | Sets the height of the widget. |
command | Sets the function to be called when the widget is used (e.g., button click). |
state | Sets the state of the widget (e.g., normal, disabled). |
Advanced Widgets
Command | Description |
---|
Menu(master) | Creates a menu widget. |
Menubutton(master) | Creates a menubutton widget. |
Checkbutton(master, text="", variable=var) | Creates a checkbutton widget. |
Radiobutton(master, text="", variable=var, value=val) | Creates a radiobutton widget. |
Scale(master, from_, to) | Creates a slider widget. |
Listbox(master) | Creates a listbox widget. |
Scrollbar(master) | Creates a scrollbar widget. |
OptionMenu(master, variable, *values) | Creates a dropdown menu. |
Spinbox(master, from_, to) | Creates a spinbox widget. |
PanedWindow(master) | Creates a paned window widget. |
LabelFrame(master, text="") | Creates a labeled frame widget. |
Message(master, text="") | Creates a message widget. |
Toplevel(master) | Creates a new window (dialog). |
This table provides a broad overview of Tkinter commands and options for creating and managing widgets within a Tkinter application. For detailed usage, the official Tkinter documentation should be referred to.
great
ReplyDelete