Skip to content

[Question] Click event triggering outside of control #2629

Answered by mghiggins
mghiggins asked this question in Q&A
Discussion options

You must be logged in to vote

The trick was wrapping the Canvas in a Container, and being careful to specify the dimensions of the container to limit the scope of the click event. Here's the code that works:

import flet as ft
import flet.canvas as cv
import os


def click(e):
    print('here click')


def main(page: ft.Page):
    brd = ft.Image('bgboard_empty.png', width=1000, height=500, fit=ft.ImageFit.FILL)
    
    gd = ft.GestureDetector(on_tap=click)
    canvas_container = ft.Container(
        width=30,
        height=30,
        left=600,
        top=235, 
        content=cv.Canvas(
            [cv.Rect(x=0, y=0, width=30, height=30, paint=ft.Paint(style=ft.PaintingStyle.FILL, color=ft.colors.GREY))], 
       …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@mghiggins
Comment options

@ndonkoHenri
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mghiggins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed
2 participants