Site icon George的生活點滴

Flet – Icon

Icon 中程式中扮演著重要的角色,能夠吸引使用者的目光,也能更簡單明白的傳遞資訊,因此在 APP 中很常見到各式各樣的 Icon,像是各類型的 Bar、選單、按鈕及通知等等,因此學會如何使用 Icon 可以增加 UI 的美觀及使用者的體驗。

Flet 中 Icon 的使用方式如下例:


# Flet Icon
# 2024-08-13
# https://github.com/lcc728/flet/blob/main/ex_icon.py

import flet as ft

def main(page: ft.Page):
    page.add(
        ft.Icon(name=ft.icons.FAVORITE, color="red", size=50),
        ft.Icon(name=ft.icons.FAVORITE, color="red", size=50, opacity=0.5336),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINE_OUTLINED, color="red", size=50, semantics_label="Heart"),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINE_SHARP, color="red", size=50, tooltip="Heart"),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINED, color="red", size=50, rotate=45),
    )
ft.app(target=main)

Icon 這個 widget 包含的參數較其它 widget少,常用的有

其它還有:

同一個 Icon 還有好幾種變化,我們可以連上 Icon Browser 查看, 點一下你要的 icon 就會直接 copy 它的名字到剪貼簿,回到編輯器直接貼上就行了。

上面有些 Icon 的變化並沒有太大的差別,像是 FAVORITE_OUTLINE_OUTLINED 和 FAVORITE_OUTLINE_SHARP ,於是問了一下 AI,得到這樣的回答:

在 Flet 的 Icon 元件中,_OUTLINE_SHARP_OUTLINE_OUTLINED 這兩個屬性通常用來定義 Icon 的樣式,特別是輪廓線的風格。雖然它們看起來相似,但實際上有一些細微的差別。

總之,還是透過自己的設計及需求,尋找適當的 icon 吧!

執行結果:

Source Code:https://github.com/lcc728/flet/blob/main/ex_icon.py


=== English Version ===

Icons play an important role in Flet. They can attract users’ attention and convey information more easily and clearly. Therefore, various icons are commonly seen in APPs, such as different types of bars, menus and buttons. and notifications, etc. Therefore, learning how to use Icon can enhance the beauty of the UI and the user experience.

The usage of Icon in Flet is as follows:


# Flet Icon
# 2024-08-13
# https://github.com/lcc728/flet/blob/main/ex_icon.py

import flet as ft

def main(page: ft.Page):
    page.add(
        ft.Icon(name=ft.icons.FAVORITE, color="red", size=50),
        ft.Icon(name=ft.icons.FAVORITE, color="red", size=50, opacity=0.5336),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINE_OUTLINED, color="red", size=50, semantics_label="Heart"),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINE_SHARP, color="red", size=50, tooltip="Heart"),
        ft.Icon(name=ft.icons.FAVORITE_OUTLINED, color="red", size=50, rotate=45),
    )
ft.app(target=main)

The Icon widget has fewer parameters than other widgets. The most common ones are

Others include:

There are several variations of the same icon. We can connect to the Icon Browser to view them. Click on the icon you want and it will copy its name directly to the clipboard. Just go back to the editor and paste it directly.

It is better to find the appropriate icon based on your own design and needs!

Result:

Source Code:https://github.com/lcc728/flet/blob/main/ex_icon.py

Exit mobile version