Table summarizing some common functions in the tkinter
library along with examples:
Function | Description | Example |
---|---|---|
Tk() | Creates the main window of the application. | root = tk.Tk() |
Button() | Creates a button widget. | button = tk.Button(root, text="Click Me") |
Label() | Creates a label widget. | label = tk.Label(root, text="Hello, World!") |
Entry() | Creates an entry widget for user input. | entry = tk.Entry(root) |
pack() | Organizes widgets in blocks before placing them. | button.pack() |
grid() | Organizes widgets in a table-like structure. | button.grid(row=0, column=0) |
place() | Places widgets at specific positions. | button.place(x=10, y=10) |
configure() | Configures widget properties after creation. | button.configure(text="New Text") |
bind() | Binds a function to an event on a widget. | button.bind("<Button-1>", my_function) |
destroy() | Destroys a widget and removes it from the GUI. | button.destroy() |
get() | Retrieves the current value of a widget. | entry_text = entry.get() |
insert() | Inserts text into an Entry widget. | entry.insert(0, "Initial Text") |
update() | Updates the GUI to reflect changes. | root.update() |
after() | Executes a function after a specified time delay. | root.after(1000, my_function) |
withdraw() | Withdraws the main window from the screen. | root.withdraw() |
geometry() | Sets the size and position of the main window. | root.geometry("400x300+100+100") |
title() | Sets the title of the main window. | root.title("My App") |
These examples are simplified and assume that you've already imported the tkinter
library as tk
and created the main window (root
). You can further explore these functions and their parameters in the official tkinter
documentation for more detailed usage.
Comments
Post a Comment