Skip to content

Image

An Image widget displays an image in the app. The image can be set by providing the path and filename of the image file when creating the Image widget, or by setting the image property of the Image widget after it has been created.

GooeyPie cannot resize your image for you, so you should make sure to use an image that is the appropriate size for your app. Supported image formats are PNG, JPEG and GIF.

Examples

Theme Switcher

An image with a transparent backgroung works well when the theme of the app might change. This image is from Wikimedia Commons.

theme_switch.py
import gooeypie as gp
def toggle_theme(event):
"""Toggles the theme of the application."""
if app.theme == "light":
app.theme = "dark"
else:
app.theme = "light"
app = gp.GooeyPieApp("Theme Switch")
# Create the frame and weather status image and text
weather_frame = gp.Frame()
weather_img = gp.Image("mostly-sunny.png")
weather_lbl = gp.Label("Mostly Sunny")
weather_lbl.style.font_size = 16
weather_frame.add(weather_img, 1, 1)
weather_frame.add(weather_lbl, 2, 1)
# Create switch and set initial position based on current theme
theme_switch = gp.Switch("Dark Mode")
if app.theme == "dark":
theme_switch.value = True
# Add event listener for switch
theme_switch.on_change(toggle_theme)
app.add(weather_frame, 1, 1)
app.add(theme_switch, 1, 2)
app.run()

Let there be light

This app demonstrates how the image can be changed while the app is running. When the user clicks the switch, the image changes from a light bulb that is off to a light bulb that is on. The light bulb images are from pngfind.

Importantly, the images are exactly the same size, so that when the image is swapped, the layout of the app does not change.

light_switcher.py
import gooeypie as gp
def light_switch_changed(event):
"""Changes the image based on the switch state."""
if light_switch.value == True:
light_img.image = "light-on.png"
else:
light_img.image = "light-off.png"
app = gp.GooeyPieApp("Light Switcher")
app.width = 300
# Create image widget
light_img = gp.Image("light-off.png")
# Create switch widget and set event listener
light_switch = gp.Switch("Turn on light")
light_switch.on_change(light_switch_changed)
# Add widgets to window
app.add(light_img, 1, 1)
app.add(light_switch, 1, 2)
app.run()

Creating an Image widget

my_image = gp.Image(image_path)

Parameters

  • image_path (string): The path and filename of the image to be displayed.

Properties

Name Type Description
.image string Gets or sets the path and filename of the image to be displayed.

Methods

This widget has no unique methods.

Events

This widget has no unique events. It supports the standard events listed below.

Standard events

  • .on_click
  • .on_double_click
  • .on_right_click
  • .on_middle_click
  • .on_mouse_down
  • .on_mouse_up
  • .on_mouse_enter
  • .on_mouse_leave

Styles

There are no styles associated with this widget.