【发布时间】:2021-02-11 21:27:54
【问题描述】:
大家好,我是 KivyMD 的新手,正在开发我的第一个应用程序。基本上,我需要在单击导航抽屉中的内容时打开一个新屏幕。例如,我的导航抽屉上有一个新房间按钮,我希望在单击它时打开一个新屏幕。
好的,这是我的代码
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from home_page_strings import toolbar
class EMC_WebmaApp(MDApp):
def build(self):
screen = Screen()
# theme settings
self.theme_cls.primary_palette = 'DeepPurple'
self.theme_cls.theme_style = 'Dark'
# end of theme declaration
# loaded strings
navigation_bar = Builder.load_string(toolbar)
# end of loaded strings
# addition of loaded strings to screen + return screen
screen.add_widget(navigation_bar)
return screen
# end of addition
EMC_WebmaApp().run()
这是我的字符串
toolbar = '''
Screen:
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'EMC_Webma'
left_action_items: [['menu', lambda x: navigation.set_state('open')]]
right_action_items: [['card-search', lambda x: print('pass')]]
elevation: 10
MDList:
TwoLineListItem:
text: 'Friend 1'
secondary_text: '[Recent text here]'
MDList:
TwoLineListItem:
text: 'Friend 2'
secondary_text: '[Recent text here]'
MDList:
TwoLineListItem:
text: 'Friend 3'
secondary_text: '[Recent text here]'
MDList:
TwoLineListItem:
text: 'Friend 4'
secondary_text: '[Recent text here]'
MDList:
TwoLineListItem:
text: 'Friend 5'
secondary_text: '[Recent text here]'
MDList:
TwoLineListItem:
text: 'Friend 6'
secondary_text: '[Recent text here]'
Widget:
MDNavigationDrawer:
id: navigation
BoxLayout:
orientation: 'vertical'
spacing: '8dp'
padding: '8dp'
Image:
source: 'einstein.jpg'
MDLabel:
text: 'Enwerem Melvin Confidence'
font_style: 'Subtitle2'
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: 'enweremmelvinconfidence@gmail.com'
font_style: 'Caption'
size_hint_y: None
height: self.texture_size[1]
ScrollView:
MDList:
OneLineIconListItem:
text: 'New Room'
IconLeftWidget:
icon: 'theater'
OneLineIconListItem:
text: 'Contacts'
IconLeftWidget:
icon: 'contacts'
OneLineIconListItem:
text: 'Calls'
IconLeftWidget:
icon: 'cellphone-android'
OneLineIconListItem:
text: 'Settings'
IconLeftWidget:
icon: 'settings'
OneLineIconListItem:
text: 'FAQ'
IconLeftWidget:
icon: 'frequently-asked-questions'
OneLineIconListItem:
text: 'Invite Friends'
IconLeftWidget:
icon: 'account-plus'
OneLineIconListItem:
text: 'Toggle Theme'
IconLeftWidget:
icon: 'theme-light-dark'
'''
感谢您的帮助????????????
【问题讨论】:
标签: python navigation-drawer kivymd