This is my first time trying out KivyMD. I have the following kivymd bottomnavigation tabs. I’m trying to get the name of the tab that is pressed such that I want to display a datatable etc in one of the tab, some profile functionality in another tab etc. However, when I’m trying to use the
on_tab_press
MDBottomNavigation
main.py
on_tab_press
on_tab_press
print(type(args[0])) - <class 'kivymd.uix.bottomnavigation.MDBottomNavigationItem'> print(*args) - <MDTab name='screen1', text='tab1'>
main.py
from kivymd.theming import ThemeManager class MainApp(MDApp): def build(self): theme_cls = ThemeManager() self.root = Builder.load_file("main.kv") return self.root def on_tab_press(self, *args): print(type(args[0])) print(*args) # returns # <class 'kivymd.uix.bottomnavigation.MDBottomNavigationItem'> # <MDTab name='screen1', text='tab1'>
main.kv
<BottomNav>: #name: 'hello' BoxLayout: orientation:'vertical' MDToolbar: title: 'folio' md_bg_color: .2, .2, .2, 1 specific_text_color: 1, 1, 1, 1 MDBottomNavigation: panel_color: 1,1,1,1 MDBottomNavigationItem: name: 'screen1' text: 'tab1' #icon: 'language-python' on_tab_press: app.on_tab_press(*args) #on_tab_press: app.current = 'home_screen' #MDLabel: # text: 'tab1' # halign: 'center' MDBottomNavigationItem: name: 'screen2' text: 'tab2' on_tab_press: app.on_tab_press(*args) #icon: 'language-cpp' #MDLabel: # text: 'I programming of C++' # halign: 'center' MDBottomNavigationItem: name: 'screen3' text: 'tab3' on_tab_press: app.on_tab_press(*args) #icon: 'language-javascript' MDLabel: text: 'JS' halign: 'center'
Anonymous Asked question May 14, 2021
Recent Comments