0

Как сделать, чтобы при нажатия на кнопку AirDrop выполнялась функция withdraw, которая вставляет bg на весь экран?

import asyncio
import flet as ft


async def main(page: ft.Page) -> None:
    page.title = '**********'
    page.theme_mode = ft.ThemeMode.DARK
    page.bgcolor = '#000000'
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.fonts = {'DeltaBlock': 'fonts/DeltaBlock.ttf'}
    page.theme = ft.Theme(font_family='DeltaBlock')

    score = ft.Text(value='0', size=100, data=0)
    score_counter = ft.Text(size=50, animate_opacity=ft.Animation(duration=600, curve=ft.AnimationCurve.BOUNCE_IN))
    image = ft.Image(src="photo.jpg", fit=ft.ImageFit.CONTAIN, animate_scale=ft.Animation(duration=600, curve=ft.AnimationCurve.EASE))
    bg = ft.Image(src="back.png", fit=ft.ImageFit.CONTAIN, animate_scale=ft.Animation(duration=600, curve=ft.AnimationCurve.BOUNCE_IN))

    async def score_up(event: ft.ContainerTapEvent) -> None:
        score.data += 1
        score.value = str(score.data)

        image.scale = 0.85

        await page.update_async()

        await asyncio.sleep(0.2)
        image.scale = 1
        score_counter.opacity = 0

        await page.update_async()

    ref_button = ft.ElevatedButton(text="Ref", on_click=score_up)
    task_button = ft.ElevatedButton(text="Task", on_click=score_up)
    boost_button = ft.ElevatedButton(text="Boost", on_click=score_up)
    with_button = ft.ElevatedButton(text="AirDrop", on_click=withdraw)

    await page.add_async(
        score,
        ft.Container(
            content=ft.Stack(controls=[image, score_counter]),
            on_click=score_up,
            margin=ft.Margin(0, 0, 0, 60)
        ),
        ft.Row(
            controls=[ref_button, task_button, boost_button, with_button],
            alignment=ft.MainAxisAlignment.CENTER,
            spacing=4
        )
    )

if __name__ == '__main__':
    ft.app(target=main, view=None, port=8000)

1 ответ 1

0

Вот код для замены картинки у Container

import asyncio
import flet as ft


async def main(page: ft.Page) -> None:
    page.title = '**********'
    page.theme_mode = ft.ThemeMode.DARK
    page.bgcolor = '#000000'
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.fonts = {'DeltaBlock': 'fonts/DeltaBlock.ttf'}
    page.theme = ft.Theme(font_family='DeltaBlock')

    score = ft.Text(value='0', size=100, data=0)
    score_counter = ft.Text(size=50, animate_opacity=ft.Animation(duration=600, curve=ft.AnimationCurve.BOUNCE_IN))
    image = ft.Image(src="photo.jpg", fit=ft.ImageFit.CONTAIN, animate_scale=ft.Animation(duration=600, curve=ft.AnimationCurve.EASE))
    bg = ft.Image(src="back.png", fit=ft.ImageFit.CONTAIN, animate_scale=ft.Animation(duration=600, curve=ft.AnimationCurve.BOUNCE_IN))

    async def score_up(event: ft.ContainerTapEvent) -> None:
        score.data += 1
        score.value = str(score.data)

        image.scale = 0.85

        await page.update_async()

        await asyncio.sleep(0.2)
        image.scale = 1
        score_counter.opacity = 0

        await page.update_async()

    container = ft.Container(
            content=ft.Stack(controls=[image, score_counter]),
            on_click=score_up,
            margin=ft.Margin(0, 0, 0, 60)
        ),

    def withdraw(e):
        container.content = ft.Stack([bg, score_counter])
        page.update()

    ref_button = ft.ElevatedButton(text="Ref", on_click=score_up)
    task_button = ft.ElevatedButton(text="Task", on_click=score_up)
    boost_button = ft.ElevatedButton(text="Boost", on_click=score_up)
    with_button = ft.ElevatedButton(text="AirDrop", on_click=withdraw)

    await page.add_async(
        score,
        container,
        ft.Row(
            controls=[ref_button, task_button, boost_button, with_button],
            alignment=ft.MainAxisAlignment.CENTER,
            spacing=4
        )
    )

if __name__ == '__main__':
    ft.app(target=main, view=None, port=8000)

Чтобы картинка применилась на весь экран, установите все элементы страницы внутрь контейнера (в Stack)

Ваш ответ

Нажимая «Отправить ответ», вы соглашаетесь с условиями пользования и подтверждаете, что прочитали политику конфиденциальности.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.