2017-03-05 295 views
0

这是在1“NoneType”对象没有属性“适配器”,“NoneType”对象没有属性“文本”

错误#1一3个问题:“NoneType”对象没有属性“文本”

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

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

  1. 当我点击添加按钮,我得到错误#1
  2. 当我点击删除按钮我得到错误#2
  3. 如何样式Kivy ListItemButton和微调。我已阅读文档,但无法理解!

如果我的问题冒犯了您,我很抱歉。

这里是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() 
+2

欢迎来到SO。请编辑您的Q代码和相关代码片段,而不是简单地发布链接。结帐http://stackoverflow.com/help/how-to-ask – xlm

+1

再次请编辑与[mcve]的代码,而不是指向我们的链接 –

+0

试过这样做,它没有工作。当我的代码告诉我时,它没有正确缩进。 –

回答

-1

现在已经很晚了,但我也有类似的问题。通过将此代码product_name: product_name product_list: product_list置于BoxLayout:之外,可以使此代码生效。我认为问题是由于product_list的范围。

相关问题