[英]AttributeError: 'super' object has no attribute '__getattr__' error at kivymd request app
it was running while my load file was .kv file but I cant switch screen on condition so I tried string load file but now It show this error.它正在运行,而我的加载文件是 .kv 文件,但我无法在条件下切换屏幕,所以我尝试了字符串加载文件,但现在它显示了这个错误。
File "C:\\Users\\armof\\PycharmProjects\\screen\\main.py", line 142, in logger payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids.password.text} File "kivy\\properties.pyx", line 864, in kivy.properties.ObservableDict.文件“C:\\Users\\armof\\PycharmProjects\\screen\\main.py”,第 142 行,记录器 payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids。 password.text} 文件“kivy\\properties.pyx”,第 864 行,在 kivy.properties.ObservableDict 中。 getattr AttributeError: 'super' object has no attribute ' getattr '
getattr AttributeError: 'super' 对象没有属性 ' getattr '
Thanks for your efforts :)感谢您的努力:)
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
import requests
screen_helper = """
ScreenManager:
MenuScreen:
ProfileScreen:
<MenuScreen>:
name : "login"
Image:
source:"C:/arka.png"
MDCard:
size_hint:None,None
size: 400,600
pos_hint : {"center_x":0.5,"center_y":0.5}
elevation:10
padding:25
spacing:25
orientation : 'vertical'
Image:
source:"C:/burbantgrilogo.png"
pos:300,380
MDLabel:
text:""
id:welcome_label
font_size:30
halign : 'center'
size_hint_y:None
height:self.texture_size[1]
padding_y:15
MDTextFieldRound:
id: user
hint_text:"username"
icon_right:"account"
size_hint_x:None
width: 200
font_size:18
pos_hint:{"center_x":0.5}
MDTextFieldRound:
id: password
hint_text:"password"
icon_right:"eye-off"
size_hint_x:None
width: 200
font_size:18
pos_hint:{"center_x":0.5}
password:True
MDRoundFlatButton:
text:"LOG IN"
font_size: 12
pos_hint:{"center_x":0.5}
on_press:app.logger()
MDRoundFlatButton:
text:"CLEAR"
font_size: 12
pos_hint:{"center_x":0.5}
on_press:app.clear()
Widget:
size_hint_y: None
height: 70
<ProfileScreen>:
name:"Teklif"
Image:
source:"C:/arka.png"
MDCard:
size_hint:None,None
size: 400,600
pos_hint : {"center_x":0.5,"center_y":0.5}
elevation:10
padding:25
spacing:25
orientation : 'vertical'
Image:
source:"C:/burbantgrilogo.png"
pos:300,380
MDRoundFlatButton:
text:"OPEN"
font_size: 12
pos_hint:{"center_x":0.5}
on_release: root.current = "login"
MDRoundFlatButton:
text:"NEW"
font_size: 12
pos_hint:{"center_x":0.5}
Widget:
size_hint_y: None
height: 130
"""
class MenuScreen(Screen):
pass
class ProfileScreen(Screen):
pass
sm = ScreenManager()
sm.add_widget(MenuScreen(name='login'))
sm.add_widget(ProfileScreen(name='Teklif'))
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Red"
screen = Builder.load_string(screen_helper)
return screen
def logger(self, *args):
payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids.password.text}
print(payload)
r = requests.get(f"http://burbant.com/otomasyon?Uname={self.root.ids.user.text}&psw={self.root.ids.password.text}")
print(r.text)
if r.text == 'True':
self.root.ids.welcome_label.text = f'Hoşgeldin {self.root.ids.user.text}!'
sm.switch_to(screen='Teklif')
else:
self.root.ids.welcome_label.text = f'Hatalı'
def clear(self):
self.root.ids.welcome_label.text = ""
self.root.ids.user.text = ""
self.root.ids.password.text = ""
MainApp().run()
The problem is that self.root.ids
is an empty dictionary, so trying to access any key in that empty dictionary will cause that error.问题在于
self.root.ids
是一个空字典,因此尝试访问该空字典中的任何键都会导致该错误。 The ids
that you are trying to access are in the MenuScreen
instance, which you can access using the get_screen()
method of ScreenManager
, like this:您尝试访问的
ids
位于MenuScreen
实例中,您可以使用ScreenManager
的get_screen()
方法访问该get_screen()
,如下所示:
def logger(self, *args):
menuscreen = self.root.get_screen('login')
payload = {'Uname': menuscreen.ids.user.text, 'psw': menuscreen.ids.password.text}
print(payload)
.
.
.
You have the same error elsewhere in your code.您的代码中的其他地方也有同样的错误。 Wherever you have
self.root.ids
, you will need to apply similar logic.无论您在哪里拥有
self.root.ids
,您都需要应用类似的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.