How to get the height of a simple component

What I’m trying to do:
Hi,
I’m still a new comer with Anvil. Sorry for this simple question, but it could help other beginners…
I want to get the height of a TextArea component that has just been created dynamicly in a XYpanel. This TextArea is expendable, and then can have a variable height.

What I’ve tried and what’s not working:
I’ve tried different ways, such as using its attribute .height (see the code sample), the .get_height(), but it is for canvas…
But it returns nothong or an error.
Could you help me, please ?
Thanks,
J.Marc

Code Sample:

Création of the question in column panel

        self.quest = TextArea(text=question,
                    enabled=False,
                    align="left",
                    font_size=14,
                    background="theme:Primary",     
                    foreground="theme:On Primary",
                    auto_expand=True,
                    spacing_above=None,
                    spacing_below=None,
                    )
        self.quest.tag.nom = "question"
        self.cp.add_component(self.quest, x=xx+5, y=yy, width="default")
        h = self.quest.height
        print(h)

That information is not available in the code for TextArea. You can use this method.

    node = anvil.js.get_dom_node(self.quest)
    height = node.clientHeight
2 Likes

Thank you KR1 for answering me !
Unfortunately it returns 0 !
I added at the top module: ‘import anvil.js’ is it ok?

Creation of the question in column panel

        self.quest = TextArea(text=question,
                    enabled=False,
                    align="left",
                    font_size=14,
                    background="theme:Primary",     
                    foreground="theme:On Primary",
                    auto_expand=True,
                    spacing_above=None,
                    spacing_below=None,
                    #height=120
                    )
        self.quest.tag.nom = "question"
        self.cp.add_component(self.quest, x=xx+5, y=yy, width="default")
        node = anvil.js.get_dom_node(self.quest)
        height = node.clientHeight
        print("HEIGHT: ", height)

I made some other tries, but in vain.
Any ideas?
Thanks !

Its clientHeight is zero until it’s on the screen. If you’re doing this inside an __init__ you’d need to wait until the show event fires.

2 Likes

Yes, you can’t do it in __init__. It’s not “visible” at this point so no height. And sorry about import anvil.js I forgot to mention it. :slight_smile:

Thank you very much Stucork & KR1 for your support !
It worked !
JM :ok_hand: :grinning:

1 Like