Created
April 24, 2024 13:43
-
-
Save ochilab/16fc4b3791927087a693df832770ca1a to your computer and use it in GitHub Desktop.
Fletで画像を表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flet as ft | |
import os | |
#絶対パスで指定する場合 | |
#カレントディレクトリを取得 | |
#cDir=os.getcwd() | |
#img1=cDir+"/kdix.jpg" | |
#img2=cDir+"/icore.jpg" | |
#相対パスで指定する場合 | |
img1="./kdix.jpg" | |
img2="./icore.jpg" | |
def main(page: ft.Page): | |
page.title = "Images Example" | |
page.theme_mode = ft.ThemeMode.LIGHT | |
page.padding = 50 | |
page.update() | |
img = ft.Image( | |
src=img1, | |
width=100, | |
height=100, | |
fit=ft.ImageFit.CONTAIN, | |
) | |
#ボタンを押したら画像を切り替える | |
def button_clicked(e): | |
img.src=img2 | |
page.update() | |
button =ft.ElevatedButton(text="Change",on_click=button_clicked) | |
#各コントロールをページに追加 | |
page.add(img,button) | |
ft.app(target=main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment