0
這是在1「NoneType」對象沒有屬性「適配器」,「NoneType」對象沒有屬性「文本」
錯誤#1一3個問題:「NoneType」對象沒有屬性「文本」
錯誤#2:「NoneType」對象有沒有屬性「適配器」
我一直在試圖調試這幾個小時
- 當我點擊添加按鈕,我得到錯誤#1
- 當我點擊刪除按鈕我得到錯誤#2
- 如何樣式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()
歡迎來到SO。請編輯您的Q代碼和相關代碼片段,而不是簡單地發佈鏈接。結帳http://stackoverflow.com/help/how-to-ask – xlm
再次請編輯與[mcve]的代碼,而不是指向我們的鏈接 –
試過這樣做,它沒有工作。當我的代碼告訴我時,它沒有正確縮進。 –