Image Property - alejandroautalan/pygubu-designer GitHub Wiki
Image property
Some tk widgets have an image property. In pygubu, this property accepts an image file name that will be used when the widget is created.
Using images in pygubu
To define an image, use the image selector located to the right of the property editor. The image name will be used as the 'key' for the selected image and saved into the *.ui file.
By default, the builder will search for images in the same directory of the specified ui file. Alternatively, you can specify different resource folders using the method add_resource_path(path). Those additional paths will be used to search for an image.
You must call add_resource_path before creating any widget that requires your custom image.
In code you can retrieve a reference of the tkinter image using the method get_image(name)
The image types you can use will depend on the tk version installed.
Example 1: Using image property
Full example code here.
...
def __init__(self, master=None):
# 1: Create a builder
self.builder = builder = pygubu.Builder()
# 2: Load an ui file
builder.add_from_file(PROJECT_UI)
# 3: Set images path before creating any widget
builder.add_resource_path(PROJECT_PATH)
# 4: Create the widget using self.master as parent
self.mainwindow = builder.get_object("mainwindow", master)
...