Tkinter Widget Library

Welcome to the official Tkinter Widget Reference. This guide provides a detailed overview of the most common Tkinter widgets supported by the TkinterBuilder, complete with descriptions and code examples to help you get started. This is not an exhaustive list as the TkinterBuilder contains many more widgets, the purpose of this list is to familiarise yourself with the most common widgets.

Basic Widgets

These are the most fundamental building blocks for any user interface.

Label

The `Label` widget is used to display a single line of static text or an image. It's non-interactive and is typically used to provide information to the user.

# Example of a Label widget
label = tkinter.Label(root, text="Hello, World!")
label.pack()

Button

The `Button` widget is used to trigger an action when clicked. You can associate a Python function with a button, which will be executed upon a click event.

# Example of a Button widget
def on_click():
    print("Button was clicked!")

button = tkinter.Button(root, text="Click Me", command=on_click)
button.pack()

Entry

The `Entry` widget provides a single-line text box for users to input a small amount of text, such as a name or a password.

# Example of an Entry widget
entry = tkinter.Entry(root, width=30)
entry.pack()

Visualize These Widgets Instantly

Want to see how these widgets look and feel without writing any code? Use the Tkinter GUI Designer to drag, drop, and customize every property in real-time.

Container Widgets

These widgets are designed to hold and organize other widgets within the application window.

Frame

The `Frame` widget is a rectangular container used to group and organize other widgets. It's essential for structuring complex layouts.

# Example of a Frame widget
frame = tkinter.Frame(root, borderwidth=2, relief="sunken")
frame.pack()

Toplevel

The `Toplevel` widget is used to create a new, separate window that is managed by the main application window. It's perfect for dialog boxes or pop-ups.

# Example of a Toplevel window
toplevel = tkinter.Toplevel(root)
toplevel.title("New Window")

Advanced Widgets

These widgets provide more complex functionality for user interaction.

Listbox

The `Listbox` widget is used to display a list of items from which a user can select one or more options.

# Example of a Listbox widget
listbox = tkinter.Listbox(root)
listbox.insert(1, "Python")
listbox.insert(2, "Tkinter")
listbox.pack()

Canvas

The `Canvas` widget is a highly versatile space used for drawing shapes, creating custom graphics, or placing other widgets at specific coordinates.

# Example of a Canvas widget
canvas = tkinter.Canvas(root, width=200, height=100)
canvas.create_line(0, 0, 200, 100)
canvas.pack()

Conclusion

This reference covers some of the most essential Tkinter widgets. By combining these components, you can build powerful and interactive desktop applications. Be sure to explore all the customizable properties for each widget to tailor them to your application's needs.