【发布时间】:2021-08-13 17:52:10
【问题描述】:
我想通过按下按钮并检查文本框是否为空来更改屏幕。 这是我的 kv 文件:
test.kv:
ScreenManager:
id: sc_m
Screen:
name: 'welcome'
MDLabel:
text: 'WeLCOME'
halign: 'center'
font_style: 'H3'
color: (1, 1, 1, 1)
pos_hint: {'center_x': 0.5, 'center_y':0.8}
MDTextField:
id: textbox
hint_text: "The text box should not be empty"
text:""
pos_hint: {'center_x': .5, 'center_y': .5}
MDRoundFlatIconButton:
text: "OK"
icon: "folder"
pos_hint: {'center_x': .5, 'center_y': .3}
on_press: app.callback()
Screen:
name:'screen2'
MDLabel:
text: 'WeLCOME'
halign: 'center'
font_style: 'H3'
color: (1, 1, 1, 1)
pos_hint: {'center_x': 0.5, 'center_y':0.8}
这是我的python代码:
main.py:
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivymd.app import MDApp
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style="Dark"
self.theme_cls.primary_palette="Cyan"
return Builder.load_file('test.kv')
def callback(self):
text = self.root.ids.textbox.text
if len(text)==0:
print('The text box should not be empty')
else:
self.root.ids.sc_m.current='screen2'
MainApp().run()
我遇到的错误:
错误:
AttributeError: 'super' object has no attribute '__getattr__'
请帮帮我!
请不要阅读文章的其余部分 我不知道该说什么了,因为它在发布时出错! '''看起来你的帖子主要是代码;请添加更多详细信息。'''
【问题讨论】: