Change the width of the buttons

How can I change the size/width of the buttons with code?
The docs only say about the attributes of the buttons:
" width - string: The width of this Button, or “default” to have the width set by the container."
(Anvil Docs | anvil)
But what sort of string? Where can I find that information?

My different tries (“small”, “15px” etc.) didn’t change anything.

1 Like

I didn’t find the solution, but I managed to work around:
I changed the default width of the buttons in the CSS template (unfortunately, this applies then to all the buttons).

This is how I did it:
Select “assets” on the menu on the left, then theme.css on the top of the page. Search for “button” in the css-text. There, under “padding”, change the second of the pixel elements , who stands for the width.

You can use an integer to change the .width property, like self.button_1.width = 250

It is kind if misleading that it says it takes a string type, but the default value is literally a string called 'default' which is supposed to take its width from its parent container (for buttons).

If I had to guess, the documentation for this was auto-generated, and assigned it the string value from the word ‘default’.

image

This should probably say :

width - string, int

Thank you :slight_smile:
I tried an int, but it seems to have no effect.
Maybe it’s because of the xy Panel (when I tried with a different test project, it seemed to work).
Fortunately it works somehow when I change the css (for the moment, it’s good enough like that for me).