[Python] Kivy not displaying images: "Image not found" error for all image paths

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm new to Kivy, and each time I try to display an image in my app, I get an "Image not found" error. I tried using different image files, but none of them seem to work. I still can't figure out why Kivy isn't loading the images.

    I'm using Kivy version 2.3.0. The images are located in the same folder as the Python file or in subdirectories. I've tried using absolute paths as well, but the issue persists.

    import os
    from kivy.uix.image import Image
    from kivy.uix.boxlayout import BoxLayout
    from kivy.app import App

    class MyApp(App):
    def build(self):
    image_path = "kivymd/images/transparent.png"

    layout = BoxLayout()

    if os.path.exists(image_path):
    print(f"Image found: {image_path}")
    img = Image(source=image_path)
    layout.add_widget(img)
    else:
    print(f"Image not found: {image_path}")

    return layout

    if __name__ == "__main__":
    MyApp().run()

    Continue reading...

Compartilhe esta Página