' NoneType'对象没有属性' adapter',' NoneType'对象没有属性' text'

时间:2017-03-05 12:42:17

标签: python kivy

这是1中的3个问题。

错误#1:' NoneType'对象没有属性' text'

错误#2:' NoneType'对象没有属性'适配器'

我一直在尝试调试这几个小时

  1. 当我点击添加按钮时,我收到错误#1
  2. 当我点击删除按钮时,我收到错误#2
  3. 如何设置Kivy ListItemButton和Spinner的样式。我已阅读文档但无法理解!
  4. 如果我的问题冒犯了你,我很抱歉。

    这里是github存储库:https://github.com/CoreElites/nairamanager

    谢谢

    这是kivy文件:nairamanager.kv

    <ViewEditProducts>:
    
    BoxLayout:
        product_name: product_name
        product_list: product_list
        orientation: "vertical"
        size: root.size
        BoxLayout:
            orientation: "horizontal"
            size_hint: (1,None)
            height: root.height*.1
            BackButton:
                id: back_button
                markup: True
                align: "center"
                font_size: "50sp"
                size_hint: (.1,1)
                on_press:
                    root.manager.current = "news_feed_screen"
                    root.manager.transition.direction = "left"
            TopLabel:
                text: "[b]View Edit Products[/b]"
                halign: "left"
                markup: True
                font_size: "15sp"
                font_name: "Arimo"
        BoxLayout:
            orientation: "horizontal"
            size_hint: (1,None)
            height: (root.height*.07)+self.padding[1]+self.padding[3]
            spacing: 10
            padding: (root.width*.25,root.height*.1,root.width*.25,root.height*.03)
            UniTextInput:
                id: product_name
                hint_text: "Product Name"
            GreenButton:
                text: "Add"
                size_hint: (.3,1)
                on_press: root.add_product()
            GreenButton:
                id: delete_green_button
                text: "Delete"
                size_hint: (.3,1)
                on_press: root.delete_product()
        BoxLayout:
            orientation: "vertical"
            size_hint: (1,root.height*.3)
            padding: (root.width*.25,0,root.width*.25,root.height*.1)
            ListView:
                id: product_list
                adapter:
                    ListAdapter(data=[str(i) for i in range(1,32)], selection_mode="multiple", cls=ListItemButton)
    

    这是实际代码:

    # -*- coding: utf-8 -*-
    
    # import kivy configuration file
    from kivy.config import Config
    # Config.set("graphics", "resizable", 0)
    
    import kivy
    
    # kivy version in use
    kivy.require("1.9.1")
    
    # importing needed classes
    from kivy.app import App
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.scrollview import ScrollView
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.anchorlayout import AnchorLayout
    from kivy.uix.label import Label
    from kivy.core.text import LabelBase
    from kivy.uix.button import Button
    from kivy.uix.widget import Widget
    from kivy.core.window import Window
    from kivy.core.window import WindowBase
    from kivy.uix.image import Image
    from kivy.properties import ObjectProperty,ListProperty,StringProperty
    from kivy.uix.image import Image
    from kivy.uix.listview import ListItemButton
    from kivy.adapters.listadapter import ListAdapter
    from kivy.uix.screenmanager import                ScreenManager,Screen,FadeTransition,FallOutTransition,WipeTransition,NoTransition,SlideTransition,RiseInTransition,SwapTransition
    
    # Change the background color of window
    Window.clearcolor = (1,1,1,1)
    
    
    class LoginSignUp(Screen):
        pass
    
    class Login(Screen):
        pass
    
    class SignUp(Screen):
        pass
    
    class SignUpTerms(Screen):
        pass
    
    class NewsFeed(Screen):
        pass
    
    class ViewEditProfile(Screen):
        pass
    
    class ViewEditProducts(Screen):
        product_name = ObjectProperty()
        product_list = ObjectProperty()
    
        def add_product(self):
            # Get product name
            product_name = self.product_name.text
    
            # Add to list
            self.product_list.data.extend([product_name])
    
            # Refresh list
            self.product_list._trigger_reset_populate()
    
        def delete_product(self,*args):
    
            # If item selected
            if self.product_list.adapter.selection:
    
                # Get the text from selected
                selection = self.product_list.adapter.selection[0].text
    
                # Remove the item
                self.product_list.remove(selection)
    
                # Refresh list
                self.product_list._trigger_reset_populate()
    
    class ProductList(ListItemButton):
        pass
    
    
    class ViewEditExpenditures(Screen):
        pass
    
    class ViewEditAssetsLiabilities(Screen):
        pass
    
    class GetLoan(Screen):
        pass
    
    class FinancialStatement(Screen):
        pass
    
    class ProfitLossStatement(Screen):
        pass
    
    class BalanceSheet(Screen):
        pass
    
    class SalesForecast(Screen):
        pass
    
    class About(Screen):
        pass
    
    # Screen management
    class ScreenManagement(ScreenManager):
    
        # Set property for screens
        transition = NoTransition()
        login_signup = ObjectProperty(None)
        login = ObjectProperty(None)
        signup = ObjectProperty(None)
        signup_terms = ObjectProperty(None)
        view_edit_profile = ObjectProperty(None)
        view_edit_products = ObjectProperty(None)
        view_edit_expenditures = ObjectProperty(None)
        view_edit_assets_liabilities = ObjectProperty(None)
        get_loan = ObjectProperty(None)
        financial_statement = ObjectProperty(None)
        profit_loss_statement = ObjectProperty(None)
        balance_sheet = ObjectProperty(None)
        sales_forecast = ObjectProperty(None)
        news_feed = ObjectProperty(None)
        about = ObjectProperty(None)
    
    class NairaManagerRegister(Screen):
        pass
    
    
    class NairaManagerApp(App):
        icon = "images/favicon_32.png"
        title = "Naira Manager"
    
        def build(self):
            return ScreenManagement()
    
    if __name__ == "__main__":
        LabelBase.register(name="Roboto",     fn_regular="fonts/roboto_regular.ttf", fn_bold="fonts/roboto_bold.ttf")
        LabelBase.register(name="Arimo", fn_regular="fonts/arimo_regular.ttf", fn_bold="fonts/arimo_bold.ttf")
        LabelBase.register(name="Webdings", fn_regular="fonts/webdings.ttf")
        NairaManagerApp().run()
    

1 个答案:

答案 0 :(得分:-1)

现在已经很晚了,但我遇到了类似的问题。通过将此代码product_name: product_name product_list: product_list置于BoxLayout:之外,可以使此代码正常工作。我认为问题是由于product_list的范围。