英文:
Creating a User-Friendly Link Selector in Taipy: How to Display a List of Links in a Selector
问题
我想创建一个小型的Taipy应用,我可以在其中从选择器、表格或切换按钮中选择图像。
我有一列图像链接,我需要显示它们,以便用户可以选择其中一个选项。是否有一种方法可以使用包含图像链接和文本的列表,并在用户友好的界面(UI)中显示它们?
英文:
I want to create a little Taipy application where I would be able to choose an image from a selector, table, or toggle.
I have a list of image links that I need to display where users can choose one of the options. Is there a way to use a list with image links and texts and display it in a user-friendly interface (UI)?
答案1
得分: 2
你可以在Taipy中使用图标进行此操作,如果你愿意的话。示例在文档这里中。然后可以显示一列带有一些文本的图像(图标)。
下面的代码是应用此功能以获取图像链接的一个小示例。请注意,也可以通过提供本地图像的路径来实现。
from taipy.gui import Gui, Icon
img_1 = "https://s18670.pcdn.co/wp-content/uploads/GettyImages-1135297525.jpg"
img_2 = "https://3.bp.blogspot.com/_kSiL_6q6sXI/TSjKjZRi_nI/AAAAAAAAAg0/DAWJ7Omn1c8/s640/2011_tropical_rainforest_animals_pictures_jaguar.jpg"
img_3 = "https://3.bp.blogspot.com/-qYR8Mv0vdjA/UBAAwoaggQI/AAAAAAAAANs/p6bddoHCVI0/s1600/Ocean-life-wallpapers-marine-life-on-the-seabed-like-fish-plants-animals-hd-wallpaper-02.jpg"
list_img = [(img_1, Icon(img_1, "Image 1")),
(img_2, Icon(img_2, "Image 2")),
(img_3, Icon(img_3, "Image 3"))]
selected_image = list_img[0]
md = """
<|{selected_image}|selector|lov={list_img}|
<|{selected_image[0]}|image|>
"""
Gui(md).run()
英文:
You can use Icon in Taipy for this use if you like. An example is in the doc here. It is then possible to display a list of images (Icon) with some text.
The code below is a little example of applying this for image links. Note that it can also work by providing the path to a local image.
from taipy.gui import Gui, Icon
img_1 = "https://s18670.pcdn.co/wp-content/uploads/GettyImages-1135297525.jpg"
img_2 = "https://3.bp.blogspot.com/_kSiL_6q6sXI/TSjKjZRi_nI/AAAAAAAAAg0/DAWJ7Omn1c8/s640/2011_tropical_rainforest_animals_pictures_jaguar.jpg"
img_3 = "https://3.bp.blogspot.com/-qYR8Mv0vdjA/UBAAwoaggQI/AAAAAAAAANs/p6bddoHCVI0/s1600/Ocean-life-wallpapers-marine-life-on-the-seabed-like-fish-plants-animals-hd-wallpaper-02.jpg"
list_img = [(img_1, Icon(img_1, "Image 1")),
(img_2, Icon(img_2, "Image 2")),
(img_3, Icon(img_3, "Image 3"))]
selected_image = list_img[0]
md = """
<|{selected_image}|selector|lov={list_img}|>
<|{selected_image[0]}|image|>
"""
Gui(md).run()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论