Đỗ Uyên
Đỗ Uyên

Reputation: 1

Dear PyGUI <built-in function add_static_texture> returned a result with an exception set

enter image description here

Problem:

I'm coding a movie search program. I'm having trouble displaying the poster when clicking on any genre.

Python Exception message:

Error loading texture for poster/155.jpg: <built-in function 
add_static_texture> returned a result with an exception set

Attempted Solutions

I tried removing:

posterImg = dpg.add_static_texture(width2, height2, data2, 
                                   parent="Genresults_list")
dpg.add_image(poster_path, width2, 
              height2,parent="Genresults_list")

and I realized there seems to be an issue with loading the image. Before posting here, I tried loading the image in a different context and it worked fine (meaning the image file exists and is not corrupted).

This is my first time using Dear PyGUI, so there's a lot I'm still unsure about. Any help would be greatly appreciated.

Code:

def genre_menu_callback(sender, app_data, user_data):
    genre = user_data
    movies = fbg.find_top_movies_by_genre(genre.lower())  # Get movie list

    if not dpg.does_item_exist("Genresults_list"):
        print("Error: 'Genresults_list' does not exist!")
        return

    dpg.delete_item("Genresults_list", children_only=True)  # Clear old results

    if movies:
        row_counter = 0  
        current_row = None  
        for movie in movies:
            poster_path = f"poster/{movie['id']}.jpg"
            if os.path.exists(poster_path):
                try:
                    width2, height2, channels2, data2 = dpg.load_image(poster_path)
                    # Create static texture
                    posterImg = dpg.add_static_texture(width2, height2, data2, parent="Genresults_list")
                    dpg.add_image(poster_path, width2, height2,parent="Genresults_list")
                except Exception as e:
                    print(f"Error loading texture for {poster_path}: {e}")
                    posterImg = None
            else:
                print(f"Poster file not found: {poster_path}")
                posterImg = None

            # Start a new row if needed
            if row_counter == 0:
                try:
                    current_row = dpg.group(horizontal=True, horizontal_spacing=30, parent="Genresults_list")
                except Exception as e:
                    print(f"Error creating new row: {e}")
                    current_row = None

            # Add movie details
            if current_row:
                try:
                    with dpg.group(parent=current_row):
                        if posterImg:
                            dpg.add_image(posterImg, width=100, height=150)
                        title_movie = dpg.add_text(f"{movie['title']}", wrap=120)
                        dpg.bind_item_font(title_movie, movieText)

                        title_vote = dpg.add_text(f"{movie['vote_average']} ★")
                        dpg.bind_item_font(title_vote, movieText)
                except Exception as e:
                    print(f"Error adding movie details for {movie['title']}: {e}")

            row_counter += 1
            if row_counter >= 5:  # Reset for a new row
                row_counter = 0
    else:
        dpg.add_text(f"Không tìm thấy phim nào trong thể loại '{genre}'", parent="Genresults_list")

    switch_ui("Primary Window", "Genre UI")

Upvotes: 0

Views: 47

Answers (0)

Related Questions