Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create tabs in NiceGUI 1.1? #251

Closed
JS-Aibel opened this issue Jan 17, 2023 · 10 comments
Closed

How to create tabs in NiceGUI 1.1? #251

JS-Aibel opened this issue Jan 17, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@JS-Aibel
Copy link

Hi,

I am looking for a more single-page application approach for my GUI, and for that, tabs would be nice to have.
In this post #133 (comment) you are showing how to create tabs in NiceGui.

1. How do we give the different tabs content?

2. Is it possible to use “Q-tabs” within the NiceGui Page Layout?
NiceGUI
Layout Header and Footer | Quasar Framework

single-page application
I think having the option to use tabs will make it easier to design a single-page application (SPA). SPAs will in my opinion be a good fit when NiceGui start supporting desktop, ref. Provide Desktop Mode · Discussion #89 · zauberzeug/nicegui (github.com)

@falkoschindler
Copy link
Contributor

Here is a minimum example combining QTabs with QTabPanels. Using a generic event subscription .on('update:model-value', ...) we can handle tab changes and set the new model-value for both the tabs and the panels:

def handle_change(msg: dict) -> None:
    name = msg['args']
    tabs.props(f'model-value={name}')
    panels.props(f'model-value={name}')

with Element('q-tabs').on('update:model-value', handle_change) as tabs:
    for name in ['A', 'B', 'C']:
        Element('q-tab').props(f'name={name} label={name}')

with Element('q-tab-panels').props('model-value=A animated') as panels:
    for name in ['A', 'B', 'C']:
        with Element('q-tab-panel').props(f'name={name}'):
            ui.label(f'Content of {name}')

Tabs and panels can be placed independently of each other. So you can wrap the tabs with a with ui.header():.

@falkoschindler falkoschindler self-assigned this Jan 20, 2023
@falkoschindler falkoschindler added this to the Later milestone Jan 23, 2023
@falkoschindler falkoschindler added the enhancement New feature or request label Jan 23, 2023
@falkoschindler falkoschindler changed the title How to create tabs in NiceGUI 1.1.2? How to create tabs in NiceGUI 1.2? Feb 10, 2023
@falkoschindler falkoschindler changed the title How to create tabs in NiceGUI 1.2? How to create tabs in NiceGUI 1.1? Feb 10, 2023
@rodja
Copy link
Member

rodja commented Feb 10, 2023

I just pushed a new example combining a foldable menu with tabs: 5e1610b. Still, on this issue we should think about a nicer integration of tabs.

falkoschindler added a commit that referenced this issue Feb 10, 2023
@rbeeli
Copy link
Contributor

rbeeli commented Feb 11, 2023

+1 A very important component IMO. Good stuff.

@falkoschindler falkoschindler modified the milestones: Later, v1.1.8 Feb 13, 2023
falkoschindler added a commit that referenced this issue Feb 13, 2023
falkoschindler added a commit that referenced this issue Feb 13, 2023
@falkoschindler
Copy link
Contributor

I implemented an API for tabs and tab panels on the tabs branch.

You can try it out as follows:

with ui.tabs() as tabs:
    ui.tab('Home', icon='home')
    ui.tab('About', icon='info')

with ui.tab_panels(tabs, value='Home'):
    with ui.tab_panel('Home'):
        ui.label('This is the first tab')
    with ui.tab_panel('About'):
        ui.label('This is the second tab')

@rodja
Copy link
Member

rodja commented Feb 14, 2023

Great! Merged into main.

@rodja rodja closed this as completed Feb 14, 2023
rodja added a commit that referenced this issue Feb 15, 2023
@rafo
Copy link

rafo commented May 9, 2023

@falkoschindler So the Example should be modified?

@falkoschindler
Copy link
Contributor

@rafo What example do you mean? Why should it be modified?

@rafo
Copy link

rafo commented May 9, 2023

@falkoschindler Sorry, pasted the wrong link. Should be https://github.com/zauberzeug/nicegui/blob/main/examples/menu_and_tabs/main.py

I will fix my #251 (comment)

@rafo
Copy link

rafo commented May 9, 2023

BTW: @falkoschindler @rodja nicegui is wonderful!

@falkoschindler
Copy link
Contributor

@rafo Oh yes, we need to review and update some of our examples. With NiceGUI's more recent features, some of them surely can be simplified. That's a great opportunity for a pul request, by the way. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants