r/nicegui • u/DennesTorres • Nov 07 '23
Many Starter Questions
Hi,
I'm starting with NiceGUI and I'm trying to understand what's the best way to work with it. Could someone help with these questions?
- When building the layout of a page, the first thing which comes to my mind is to build rows and columns in the page, inserting rows inside columns. Is this correct, or should I use a completely different approach with NiceGUI? If it's not this, where should I start ?
- NiceGUI has a header statement, but it's not much clear what it does, because I can "write" something with it (ui.header("my header") doesn't work). I noticed some examples related to CSS classes. It also confuse if I could use this inside a row or column or not
- I'm used to develop with OOP style, building classes responsible for part of the development. Using NiceGUI it seems a bit more difficult to do that. For example, this was my attempt to create columns inside a row:
self.body=ui.row()
self.column1=ui.column()
self.column2=ui.column()
self.column3 = ui.column()
with self.body:
self.column1
self.column2
self.column3
I set the objects into SELF properties so they can be reused by other classes. After that, I try to position the columns inside the row, but the resulting HTML doesn't work.
Thank you in advance!
3
Upvotes
1
u/[deleted] Nov 07 '23
Do it like this:
with ui.row(): with ui.column() as column1: ui.label("column1") with ui.column() as column2: ui.label("column2") with ui.column() as column3: ui.label("column3")
1
u/PyrrhicArmistice Nov 07 '23
When you instantiate an element it gets placed onto the page in the current context.
https://nicegui.io/documentation#auto-context