首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决奇维错误: AttributeError:'super‘对象没有属性'__getattr__’

如何解决奇维错误: AttributeError:'super‘对象没有属性'__getattr__’
EN

Stack Overflow用户
提问于 2021-05-12 21:53:10
回答 1查看 119关注 0票数 2

我是新来的,我创建了一个使用2旋转器的表单,第一个旋转器包含一个值列表,当它被选中时,它将从.py文件中调用一个函数,并更改第二个旋转器的值。但是,每当我从第一个旋转器中选择一个值时,就会显示"AttributeError:'super‘object没有属性'getattr'"。我试过很多东西,但都没能成功,请任何尝试都是感激的。

我的.py文件:

代码语言:javascript
复制
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen

#dummy screen
class Blank(Screen):
    def on_enter(self):
        Clock.schedule_once(self.change_screen)
    def change_screen(self, dt):
        if True: self.manager.current = 'page1'
        else: self.manager.current = 'menu'
        
class Page1(Screen):
    combinations_id = ObjectProperty(None)
    def spinner_func(self):
        self.ids.combinations.values = ['g','y']
    
class Menu(Screen):
    pass
    
class Profile(Screen):
    pass

class MainMenu(ScreenManager):
    pass


kv = Builder.load_file('main.kv')

class SpinApp(App):
    def build(self):
        self.other = Page1()
        return kv
        
if __name__ == '__main__':
    SpinApp().run()

**这是.kv文件:**

代码语言:javascript
复制
MainMenu:
    Blank:
    Page1:
    Menu:
    Profile:


<Menu>:
    name: 'menu'
    Label:
        text: 'MENU'
<Profile>:
    name: 'profile'
    Label:
        text: 'profile'

<Page1>:
    name: 'page1'
    BoxLayout:
        combinations_id: combinations_id
        orientation: 'vertical'
        canvas.before:
            Color:
                rgb: (253/255, 245/255, 230/255, 1)
            Rectangle:
                size: self.size
                pos: self.pos
    
        Label:
            canvas.before:
                Color:
                    rgb: (250/255, 235/255, 210/255, 1)
                Rectangle:
                    size: self.size
                    pos: self.pos
            color: 47/255, 79/255, 79/255, 1
            text: 'please fill the form for conveniency'
            font_size: 34
            italic: True
            bold: True
            size_hint_y: 0.18
        
        ScrollView:
            GridLayout:
                size: root.width, root.height
                size_hint_y: None
                height: 1200
                width: self.minimum_width
                rows: 3
                cols: 1
                spacing: 10
                    
                RelativeLayout:
                    Label:
                        text: 'User Profile'
                        size_hint: (0.45,None)
                        height: 100
                        font_size: 30
                        bold: True
                        pos_hint: {'center_x':0.332}
                        canvas.before:
                            Color:
                                rgb: (43/255, 88/255, 108/255, 1)
                            RoundedRectangle:
                                size: self.size
                                pos: self.pos
                                radius: [15]
                    
                    #form layout
                RelativeLayout:
                    size_hint_y: None
                    height: 900
                    BoxLayout:
                        orientation: 'vertical'
                        size_hint_x: None
                        width: (root.width)*0.8
                        pos_hint: {'center_x':0.5}
                        padding: [15,10,10,0]
                        canvas:
                            Color:
                                rgb: (93/255, 138/255, 168/255, 1)
                            RoundedRectangle:
                                size: self.size
                                pos: self.pos
                                radius: [20,20,20,20]
                                    
                        Label:
                            id: name
                            text: '\nName'
                            size_hint_x: None
                            size: self.texture_size
                            pos_hint: {'left': 1}
                            bold: True
                        Input_text:
                            hint_text: 'eg. AbdulAzeez Nuhu'
                                
                        Input_label:
                            text: '\nMatric Number'
                        Input_text:
                            hint_text: 'eg. se/mat-csc/19/0000'
                                
                        Input_label:
                            text: '\nSchool'
                        My_spinner:
                            id: schools_id
                            text: 'Choose your school'
                            values: ['Science', 'Education', 'Vocational', 'Technical', 'Art and Sos', 'Languages']
                            on_text: app.other.spinner_func()
                                
                        Input_label:
                            text: '\nCombination'
                        My_spinner:
                            id: combinations_id
                            text: 'Choose your Combination'
                            values: []
                            on_text: root.comb_func()
                            
                        Input_label:
                            text: '\nLevel'
                        GridLayout:
                            cols: 7
                            GridLayout:
                                cols: 2
                                CheckBox:
                                    group: 'level'
                                Label:
                                    text: '100' 
                            Label:
                                size_hint_x: 0.3
                                    
                            GridLayout:
                                cols: 2
                                CheckBox:
                                    group: 'level'
                                Label:
                                    text: '200' 
                            Label:
                                size_hint_x: 0.3
                                    
                            GridLayout:
                                cols: 2
                                CheckBox:
                                    group: 'level'
                                Label:
                                    text: '300'
                            Label:
                                size_hint_x: 1.5
                    
                RelativeLayout:
                    Round_Button:
                        text: 'Submit'
                        size_hint: (0.8, None)
                        height: 100
                        pos_hint: {'center_x':0.5, 'top':1}
                        on_release: app.root.current = 'menu'
        
<Input_label@Label>:
    size_hint_x: None
    size: self.texture_size
    pos_hint: {'left': 1,}
    bold: True
    
<Input_text@TextInput>:
    multiline: False
    size_hint_y: 0.8
    padding: [10, 10]
    background_normal: ''
    background_color: 240/255, 248/255, 1, 1
    valign: 'bottom'
    
<My_spinner@Spinner>:
    color: 0.5,0.5,0.5,1
    size_hint_y: 0.8
    text_size: self.size
    halign: 'left'
    padding: [15,15]
    background_normal: ''
    background_color: 240/255, 248/255, 1, 1

<SpinnerOption>:
    size_hint_y: None
    height: 70
    color: 1,1,1,1
    text_size: self.size
    halign: 'left'
    padding_x: 15
    background_normal: ''
    background_color: 112/255, 128/255, 144/255, 1

<Round_Button@Button>:
    background_color: (0,0,0,0)
    background_normal: ''
    canvas.before:
        Color:
            rgb: (0, 123/255, 167/255, 1) if self.state=='normal' else (0,.7,.7,1)
        RoundedRectangle:
            size: self.size
            pos: self.pos
            radius: [20,20,20,20]           

输出:

代码语言:javascript
复制
[INFO   ] [Logger      ] Record log in /storage/emulated/0/kivi/.kivy/logs/kivy_21-05-12_22.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.3 (default, Jun 15 2020, 02:19:10) 
[GCC 9.3.0]
[INFO   ] [Python      ] Interpreter at "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/bin/python3"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 2.0'>
[INFO   ] [GL          ] OpenGL vendor <b'ARM'>
[INFO   ] [GL          ] OpenGL renderer <b'Mali-400 MP'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [GL          ] NPOT texture support is available
[WARNING] [Base        ] Unknown <android> provider
[INFO   ] [Base        ] Start application main loop
[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "kivy/properties.pyx", line 860, in kivy.properties.ObservableDict.__getattr__
 KeyError: 'combinations'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/storage/emulated/0/kivi/newfile5.py", line 41, in <module>
     SpinApp().run()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/app.py", line 855, in run
     runTouchApp()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/core/window/window_sdl2.py", line 747, in mainloop
     self._mainloop()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/core/window/window_sdl2.py", line 479, in _mainloop
     EventLoop.idle()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/base.py", line 342, in idle
     self.dispatch_input()
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/base.py", line 327, in dispatch_input
     post_dispatch_input(*pop(0))
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/base.py", line 293, in post_dispatch_input
     wid.dispatch('on_touch_up', me)
   File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/uix/behaviors/button.py", line 179, in on_touch_up
     self.dispatch('on_release')
   File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/uix/spinner.py", line 196, in <lambda>
     item.bind(on_release=lambda option: dp.select(option.text))
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/uix/dropdown.py", line 275, in select
     self.dispatch('on_select', data)
   File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/uix/spinner.py", line 213, in _on_dropdown_select
     self.text = data
   File "kivy/properties.pyx", line 497, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 544, in kivy.properties.Property.set
   File "kivy/properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1096, in kivy._event.EventObservers._dispatch
   File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/kivy/lang/builder.py", line 64, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "/storage/emulated/0/kivi/main.kv", line 108, in <module>
     on_text: app.other.spinner_func()
   File "/storage/emulated/0/kivi/newfile5.py", line 21, in spinner_func
     self.ids.combinations.values = ['g','y']
   File "kivy/properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-12 22:41:40

您正在尝试引用行中不存在的id

代码语言:javascript
复制
self.ids.combinations.values = ['g','y']

我相信你试图引用的idcombinations_id。尝试将该行更改为:

代码语言:javascript
复制
self.ids.combinations_id.values = ['g', 'y']

此外,在build()方法中,行:

代码语言:javascript
复制
self.other = Page1()

正在创建Page1的新实例,但该实例并不是显示在GUI中的实例,因此可以删除该行。然后。在您的kv中,更改行:

代码语言:javascript
复制
on_text: app.other.spinner_func()

至:

代码语言:javascript
复制
on_text: root.spinner_func()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67511461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档