不断遇到一个错误,上面写着属性错误:'None Type' 对象没有属性 'text'.我不知道问题出在哪里.进行了大量研究,但没有看到任何提供任何清晰度的帖子关于这个问题.想法?
Keep running into a error that says "Attribute Error: 'None Type' object has no attribute 'text'. I have no idea where the problem is. Did a fair amount of research, but saw no posts that provided any clarity on the issue. Thoughts?
这是我的 main.py 文件
This is my main.py file
from kivy.app import App
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.popup import Popup
from kivy.uix.button import Button
import os
from kivy.uix.widget import Widget
from kivy.uix.scrollview import ScrollView
from kivy.graphics import *
from kivy.properties import ObjectProperty
class OptionMenu(GridLayout):
loadfile = ObjectProperty(None)
savefile = ObjectProperty(None)
text_input = ObjectProperty(None)
def dismiss_popup(self):
self._popup.dismiss()
def show_load(self):
content = LoadDialog(load=self.load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load file", content=content, size_hint=(0.9, 0.9))
self._popup.open()
def load(self, path, filename):
with open(os.path.join(path, filename[0])) as stream:
self.text_input.text = stream.read()
self.dismiss_popup()
def show_save(self):
content = SaveDialog(save=self.save, cancel=self.dismiss_popup)
self._popup = Popup(title="Save file", content=content,
size_hint=(0.9, 0.9))
self._popup.open()
def save(self, path, filename):
with open(os.path.join(path, filename), 'w') as stream:
stream.write(self.text_input.text)
self.dismiss_popup()
class GraphMenu(GridLayout):
pass
class UnnamedMenu(GridLayout):
pass
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
class MainController(FloatLayout):
pass
class MainApp(App):
def build(self):
rt = MainController()
return rt
Factory.register('Main', cls=MainController)
Factory.register('LoadDialog', cls=LoadDialog)
Factory.register('SaveDialog', cls=SaveDialog)
if __name__ == '__main__':
MainApp().run()
这是我的 main.kv 文件:
This is my main.kv file:
#kivy 1.0
<OptionMenu>
cols: 2
row:10
Button:
size_hint_y: 0.05
text: "Input File"
on_release: self.parent.show_load()
Button:
size_hint_y:0.05
text:"Save File"
on_release:self.parent.show_save()
TextInput:
id: text_input
text:''
RstDocument:
text: text_input.text
show_errors: True
<MainController>
BoxLayout:
orientation: 'horizontal'
Accordion:
size_hint_x: 0.3
orientation: 'vertical'
AccordionItem:
title:'Options'
OptionMenu:
id: 'AppOpt'
AccordionItem:
title:'Config'
UnnamedMenu:
id:ConfigTab
AccordionItem:
title:'Graph'
GraphMenu:
id:GraphTab
FloatLayout:
size_hint_x: 0.7
Label:
<scroller>
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
BoxLayout:
size_hint_y: None
height: 10
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
<SaveDialog>:
text_input: text_input
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
on_selection: text_input.text = self.selection and self.selection[0] or ''
TextInput:
id: text_input
size_hint_y: None
height: 30
multiline: False
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Save"
on_release: root.save(filechooser.path, text_input.text)
这是完整的错误消息和堆栈转储:
This is the full error message and stack dump:
botstrapping Kivy @ C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32
Setting Environment Variables:
#################################
GST_REGISTRY
C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32gstreamer
egistry.bin
---------------
GST_PLUGIN_PATH:
C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32gstreamerlibgstreamer-1.0
---------------
PATH:
C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32;C:UsersMy.FilesDownload
sKivy-1.8.0-py2.7-win32Python27;C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-
win32 ools;C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32Python27Scripts
;C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32gstreamerin;C:UsersAdit
.ShahDownloadsKivy-1.8.0-py2.7-win32MinGWin;C:Program Files (x86)RSA Secu
rID Token Common;C:Program Files (x86)InteliCLS Client;C:Program FilesInte
liCLS Client;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:Window
sSystem32WindowsPowerShellv1.0;C:Program FilesIntelWiFiin;C:Program F
ilesCommon FilesIntelWirelessCommon;C:Program FilesSASSharedFiles(32)For
mats;c:Program Files (x86)Microsoft SQL Server110ToolsBinnManagementStudio
;c:Program Files (x86)Microsoft SQL Server110ToolsBinn;c:Program Files (
x86)Microsoft SQL Server110DTSBinn
----------------------------------
PYTHONPATH:
C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivy;
----------------------------------
##################################
done bootstraping kivy...have fun!
running "python.exe "D:workspacekivyWorkGUImain.py""
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in C:UsersMy.Files.kivylogs
kivy_15-02-19_77.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=
Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout
=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout
=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img
_gif (img_pil ignored)
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeo
ut=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeou
t=3600s
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Display driver windib
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a8
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 4
GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <4.2.0 - Build 10.18.10.3621>
[INFO ] [GL ] OpenGL vendor <Intel>
[INFO ] [GL ] OpenGL renderer <Intel(R) HD Graphics 4400>
[INFO ] [GL ] OpenGL parsed version: 4, 2
[INFO ] [GL ] Shading version <4.20 - Build 10.18.10.3621>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load <C:UsersMy.FilesDownloadsKivy-1.8.
0-py2.7-win32kivykivydataglsldefault.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, n
ot docked
[DEBUG ] [App ] Loading kv <D:workspacekivyWorkGUImain.k
v>
[DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout
=60s
[INFO ] [Loader ] using a thread pool of 2 workers
[DEBUG ] [Cache ] register <textinput.label> with limit=None,
timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None,
timeout=60.0s
[DEBUG ] [Atlas ] Load <C:UsersMy.FilesDownloadsKivy-1.8.
0-py2.7-win32kivykivydata..dataimagesdefaulttheme.atlas>
[DEBUG ] [Atlas ] Need to load 1 images
[DEBUG ] [Atlas ] Load <C:UsersMy.FilesDownloadsKivy-1.8.
0-py2.7-win32kivykivydata..dataimagesdefaulttheme-0.png>
[DEBUG ] [ImagePygame ] Load <C:UsersMy.FilesDownloadsKivy-1.8.
0-py2.7-win32kivykivydata..dataimagesdefaulttheme-0.png>
[INFO ] [VideoGstplayer] Using Gstreamer 1.2.1.0
[INFO ] [Video ] Provider: gstplayer
[INFO ] [OSC ] using <thread> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from wm_touch
[DEBUG ] [Base ] Create provider from wm_pen
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[WARNING ] [Accordion ] not enough space for displaying all children
[WARNING ] [Accordion ] need 132px, got 100px
[WARNING ] [Accordion ] layout aborted.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.GraphMenu object at 0x07106A40> have no cols or r
ows set, layout is not triggered.
[WARNING ] [Accordion ] not enough space for displaying all children
[WARNING ] [Accordion ] need 132px, got 100px
[WARNING ] [Accordion ] layout aborted.
[WARNING ] <__main__.GraphMenu object at 0x07106A40> have no cols or r
ows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[WARNING ] <__main__.UnnamedMenu object at 0x07106810> have no cols or
rows set, layout is not triggered.
[ERROR ] unable to access to <hiberfil.sys>
Traceback (most recent call last):
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyuixfilech
ooser.py", line 122, in is_hidden
return GetFileAttributesExW(fn)[0] & FILE_ATTRIBUTE_HIDDEN
error: (32, 'GetFileAttributesEx', 'The process cannot access the file because i
t is being used by another process.')
[ERROR ] unable to access to <pagefile.sys>
Traceback (most recent call last):
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyuixfilech
ooser.py", line 122, in is_hidden
return GetFileAttributesExW(fn)[0] & FILE_ATTRIBUTE_HIDDEN
error: (32, 'GetFileAttributesEx', 'The process cannot access the file because i
t is being used by another process.')
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "D:workspacekivyWorkGUImain.py", line 76, in <module>
MainApp().run()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyapp.py",
line 792, in run
runTouchApp()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyase.py",
line 481, in runTouchApp
EventLoop.window.mainloop()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivycorewind
owwindow_pygame.py", line 381, in mainloop
self._mainloop()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivycorewind
owwindow_pygame.py", line 287, in _mainloop
EventLoop.idle()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyase.py",
line 324, in idle
self.dispatch_input()
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyase.py",
line 309, in dispatch_input
post_dispatch_input(*pop(0))
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyase.py",
line 275, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_e
vent.c:4409)
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivyuixehav
iors.py", line 110, in on_touch_up
self.dispatch('on_release')
File "_event.pyx", line 312, in kivy._event.EventDispatcher.dispatch (kivy\_e
vent.c:4359)
File "C:UsersMy.FilesDownloadsKivy-1.8.0-py2.7-win32kivykivylang.py",
line 1299, in custom_callback
exec(__kvlang__.co_value, idmap)
File "D:workspacekivyWorkGUImain.kv", line 63, in <module>
on_release: root.load(filechooser.path, filechooser.selection)
File "D:workspacekivyWorkGUImain.py", line 34, in load
self.text_input.text = stream.read()
AttributeError: 'NoneType' object has no attribute 'text'
Press any key to continue . . .
你从来没有设置过 text_input
的值,所以它仍然是默认的 None
.仅设置一个 id 并不会设置该属性.这里有几个简单的修复方法.
You never set the value of text_input
, so it is still the default None
. Just setting an id doesn't set that attribute. There are a couple easy fixes here.
首先,你可以填写那个值:
First, you can fill in that value:
<OptionMenu>:
# this sets the `text_input` attribute to the value
# of the `text_input` id below
text_input: text_input
...
TextInput:
id: text_input
...
或者,您可以通过 ids
集合访问小部件,并完全删除 text_input
属性:
Alternatively, you can access the widget via the ids
collection, and remove the text_input
attribute completely:
def load(self, path, filename):
with open(os.path.join(path, filename[0])) as stream:
# self.ids is the collection of ids for this widget rule
self.ids.text_input.text = stream.read()
self.dismiss_popup()
这篇关于Kivy 错误:属性错误:“无类型"对象没有属性“文本"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!