python - 如何通过单击python中的按钮和MDNavigationDrawer来kivyMD数据表
问题描述
当我按下按钮时出现错误AttributeError: 'MDDataTable' object has no attribute 'open'
我希望通过打开 MDNavigationDrawer 菜单并按 MDlist 中的 OneLineIconListItem 来显示 MDDatatable,但出现上述错误。如果可能,请提供帮助
如果有人可以在 kivyMD 中编写一个程序,通过点击下拉菜单中的一个项目来调用数据表,我将非常感激。.py
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen,ScreenManager
from kivy.properties import ObjectProperty
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
class MenuScreen(Screen):
pass
class ProfileScreen(Screen):
pass
sm=ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(ProfileScreen(name='profile'))
class DemoApp(MDApp):
tables = ObjectProperty(None)
def table(self):
self.tables = MDDataTable(size_hint=(0.9, 0.6),
use_pagination=True,
column_data=[
("No.", dp(30)),
("Column 1", dp(30)),
("Column 2", dp(30)),
("Column 3", dp(30)),
("Column 4", dp(30)),
("Column 5", dp(30)),
],
row_data=[
(f"{i + 1}", "1", "2", "3", "4", "5") for i in range(50)
],
)
self.tables.open()
def build(self):
return Builder.load_file("mainApp.kv")
DemoApp().run()
.kv
#:import arabic_reshaper arabic_reshaper
#:import get_display bidi.algorithm.get_display
ScreenManager:
MenuScreen:
ProfileScreen:
<MenuScreen>:
name:"menu"
MDNavigationLayout:
ScreenManager:
MDScreen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Navigation Drawer"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
size_hint:(1,.15)
BoxLayout:
pos_hint:{"center_x":0.5,"center_y":0.5}
orientation: 'vertical'
size_hint:(1,1)
MDFloatLayout:
size:root.width , root.height
padding:20
spacing:20
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('ناودانی'))
pos_hint:{'center_x':0.3,'center_y':0.15}
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('نبشی'))
pos_hint:{'center_x':0.7,'center_y':0.15}
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('پروفیل'))
pos_hint:{'center_x':0.3,'center_y':0.5}
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('ورق'))
pos_hint:{'center_x':0.7,'center_y':0.5}
on_press: app.table()
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('تیرآهن'))
pos_hint:{'center_x':0.30,'center_y':0.85}
MDRoundFlatIconButton:
icon: "android"
text: get_display(arabic_reshaper.reshape('میلگرد'))
pos_hint:{'center_x':0.7,'center_y':0.85}
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation:'vertical'
spacing:"8dp"
padding:"8dp"
Image:
source: "images/treee.jpg"
MDLabel:
text:'AliReza'
font_style:'Subtitle1'
size_hint_y:None
height:self.texture_size[1]
MDLabel:
text:'alirezafaramarzi21@gmail.com'
font_style:'Caption'
size_hint_y:None
height:self.texture_size[1]
ScrollView:
MDList:
OneLineIconListItem:
text: get_display(arabic_reshaper.reshape('قیمت ها'))
on_release:root.manager.current='profile'
IconLeftWidget:
icon: "cash-multiple"
OneLineIconListItem:
text: get_display(arabic_reshaper.reshape('تماس با ما'))
IconLeftWidget:
icon: "phone-plus"
<ProfileScreen>:
name:'profile'
MDLabel:
text:"welcome"
halign:'center'
MDRectangleFlatButton:
text: get_display(arabic_reshaper.reshape('بازگشت'))
pos_hint:{"center_x":0.5,"center_y":0.4}
on_press:
root.manager.current='menu'
root.manager.transition.direction="right"
解决方案
推荐阅读
- java - org.springframework.web.client.ResourceAccessException 同时在 Spring Boot 中模拟 POST restTemplate.exchange 方法
- java - Android Studio - DecimalFormat (java.text) - 无法正常工作
- angular - Snackbar 不适用于模态表角材料
- javascript - 异步加载数据,一键下载CSV数据,比最新检索数据落后一步
- javascript - node/fastify 不支持的媒体类型出现错误:application/x-www-form-urlencoded
- visual-studio - 我想为 Visual Studio 中的每个构建增加构建修订版本
- python - 如何设置整个 QTableWidget 的边框颜色,而不是项目
- linux - GCP VM 实例中的进程自动终止
- pdf - AppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF
- subdomain - 具有域指向的经销商 Web 应用程序