toga.ImageView not showing image under ‘if’ condition

I am trying to create an app with a dropdown menu, on click then it will show an image – code attached:

“””
My first application
“””
import toga
from Tools.scripts import startuptime
from toga.style.pack import CENTER, COLUMN, ROW, Pack, BOTTOM, TOP, LEFT
import httpx
from toga import App, Box, MainWindow
from toga import ImageView, Image

import sys

def greeting(name):
if name:
if name == “Brutus”:
return “BeeWare the IDEs of Python!”
else:
return f”Hello, {name}”
else:
return “Hello, stranger”

class HelloWorld(toga.App):
def startup(self):
main_box = toga.Box(style=Pack(direction=COLUMN))

    name_label = toga.Label(
        "Your name: ",
        style=Pack(padding=(0, 5))
    )
    self.name_input = toga.TextInput(style=Pack(flex=1))

    name_box = toga.Box(style=Pack(direction=ROW, padding=5))
    name_box.add(name_label)
    name_box.add(self.name_input)

    selection = toga.Selection(
        items=[
            {"name": "Select a muscle group"},
            {"name": "Traps"},
            {"name": "Delts"},
            {"name": "Triceps"},
            {"name": "Biceps"},
            {"name": "Forearms"},
            {"name": "Chest"},
            {"name": "Abs"},
            {"name": "Lats"},
            {"name": "Legs"},

        ],
        accessor="name",
        on_change=self.clicked,

    )

    # Select Bob explicitly
    selection.value = selection.items[0]

    # selection.value = selection.items.find("Traps")

    # Which item is currently selected? This will print "Charlie"
    print(f"Currently selected: {selection.value}")

    button = toga.Button(
        "Say Hello!",
        on_press=self.say_hello,
        style=Pack(padding=5)
    )

    image_from_path = toga.Image("anat_one.png")

    main_box.add(name_box)
    main_box.add(selection)
    main_box.add(button)
    # self.triceps(main_box, image_from_path)
    # print('no.1' + str(image_from_path))

    self.main_window = toga.MainWindow(title=self.formal_name)
    self.main_window.content = main_box
    self.main_window.show()

def clicked(self, selection):
    print("Clicked row", selection.value, "of table")
    box = toga.Box(style=Pack(direction=COLUMN))
    image_from_path = toga.Image("anat_one.png")

    if 'Triceps' in str(selection.value):
    # if 'Triceps' in str(selection.value):
        box.add(toga.ImageView(image_from_path))
        print('Triceps are proper ' + str(image_from_path))
        print('box is: ' + str(box))


async def say_hello(self, widget):
    async with httpx.AsyncClient() as client:
        response = await client.get("https://jsonplaceholder.typicode.com/posts/42")

    payload = response.json()

    self.main_window.info_dialog(
        greeting(self.name_input.value),
        payload["body"],
    )

def main():
return HelloWorld()

specifically, I added ‘on_change = self.clicked’ to the ‘selection’ dropdown menu which calls the function ‘clicked’ (also can be found in the code above):

def clicked(self, selection):
    print("Clicked row", selection.value, "of table")
    box = toga.Box(style=Pack(direction=COLUMN))
    image_from_path = toga.Image("anat_one.png")

    if 'Triceps' in str(selection.value):
    # if 'Triceps' in str(selection.value):
        box.add(toga.ImageView(image_from_path))
        print('Triceps are proper ' + str(image_from_path))
        print('box is: ' + str(box))

However, although the image exists and it shows that box.add exists, nothing appears when “Triceps” are selected from the dropdown menu

screenshot of selected dropdown option

New contributor

Wrise is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật