【发布时间】:2021-11-21 18:55:41
【问题描述】:
我正在尝试将图表添加到 KivyMD 的选项卡中,这是出现的警告,并且图表未显示在界面上。这是我从代码中收到的完整错误:
[警告] 对象“main.Tab 对象位于 0x0000011807CA3040>”的已弃用属性“”已被访问,它将在未来的版本中删除
x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [1, 2, 7, 4, 1, 6, 5, 8]
plt.plot(x, y)
y_label = 'performance'
class Tab(FloatLayout, MDTabsBase):
graph = StringProperty()
class StatsScreen(Screen):
def __init__(self, **kwargs):
super(StatsScreen, self).__init__()
self.graph = self.ids.Last_graph
self.graph.add_widget(FigureCanvasKivyAgg(plt.gcf()))
这是屏幕的 kivymd 代码:
<StatsScreen>
name: 'stats_interface'
MDFloatLayout:
size: root.width, root.height
md_bg_color: app.theme_cls.primary_light
MDLabel:
id: heading_label
text: 'Statistics'
size_hint: (0.75, 0.1)
pos_hint: {'center_x':0.5 , 'y':0.90}
bold: True
halign: 'center'
MDTabs:
size_hint: 0.95, 0.53
pos_hint: {'center_x':0.5 , 'y':0.4 }
tab_display_mode: 'text'
Tab:
name: 'Last Session'
text: 'Last Session'
FloatLayout:
id: Last_graph
Tab:
name: 'Progress Graph'
text: 'Progress Graph'
MDBoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.1
pos_hint: {'center_x':0.5, 'top':0.39}
md_bg_color: 250/255, 250/255, 250/255, 1
line_color: 0, 0, 0, 1
radius: [15, ]
MDLabel:
id: goal_grade_label
text: 'Goal Grade: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.8}
bold: True
MDLabel:
id: current_grade_label
text: 'Current Grade: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.5}
bold: True
MDBoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.2
pos_hint: {'center_x':0.5, 'top':0.28}
md_bg_color: 250/255, 250/255, 250/255, 1
line_color: 0, 0, 0, 1
radius: [18, ]
MDLabel:
text: 'Last session analysis: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.8}
bold: True
MDLabel:
id: percentage_label
text: 'Percentage: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.6}
MDLabel:
id: grade_label
text: 'Grade: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.4}
MDLabel:
id: marks_label
text: 'Total Marks: '
size: self.texture_size
pos_hint: {'x':0.05 , 'center_y':0.2}
MDTextButton:
text: 'Return'
size_hint: (0.2, 0.05)
pos_hint: {'x': 0.1, 'y': 0.02}
bold: True
MDTextButton:
text: 'Settings'
size_hint: (0.2, 0.05)
pos_hint: {'x': 0.475, 'y': 0.02}
bold: True
MDTextButton:
text: 'Topics'
size_hint: (0.2, 0.05)
pos_hint: {'x': 0.85, 'y': 0.02}
bold: True
<Tab>:
text: 'testing'
FloatLayout:
id: test_id
有没有办法解决这个错误?
【问题讨论】: