📜  icon tkiner - Python (1)

📅  最后修改于: 2023-12-03 15:15:47.032000             🧑  作者: Mango

Icon Tkinter - Python

Icon Tkinter is a Python library that allows the creation of graphical user interfaces (GUIs) using the Tkinter library. It provides developers with a variety of icons and themes to choose from, enabling them to design visually appealing and user-friendly interfaces.

Installation

The Icon Tkinter library can be installed using pip:

pip install icon-tkinter
Usage

Here is a simple example of how to use Icon Tkinter to create a GUI:

import tkinter as tk
from icon_tkinter import *

# Create the main window
root = tk.Tk()

# Create a button with a theme icon
icon_button = IconTK(root, "add-circle", command=lambda: print("Button clicked!"))
icon_button.pack()

# Run the main loop
root.mainloop()

This code will create a window with a button displaying an "add-circle" icon. Clicking on the button will print "Button clicked!" to the console.

Icon Themes

Icon Tkinter includes several built-in icon themes that provide different sets of icons to choose from. These themes can be loaded using the IconTheme class:

from icon_tkinter import IconTheme

# Load the "Tango" icon theme
theme = IconTheme("Tango")

# Get the "add" icon
add_icon = theme.get_icon("add")

# Create a button with the "add" icon
icon_button = IconTK(root, add_icon, command=lambda: print("Button clicked!"))

The following icon themes are included with Icon Tkinter:

  • Tango
  • Oxygen
  • Faenza
Custom Icons

In addition to the built-in themes, Icon Tkinter also supports the creation of custom icons. Custom icons can be defined using SVG files, and can be loaded using the IconTheme.load method:

from icon_tkinter import IconTheme

# Load a custom icon theme
theme = IconTheme.load("custom_theme.json")

# Get a custom icon
custom_icon = theme.get_icon("custom")

# Create a button with the custom icon
icon_button = IconTK(root, custom_icon, command=lambda: print("Button clicked!"))

The custom_theme.json file should define the icons using SVG files, like this:

{
    "icons": {
        "custom": {
            "svg": "custom.svg",
            "width": 24,
            "height": 24,
            "padding": 4
        }
    }
}
Conclusion

Icon Tkinter provides a simple and powerful way to add icons and themes to Python GUIs. With its built-in icon themes and support for custom icons, it offers developers a wide range of options for creating visually appealing and user-friendly interfaces.