我有一个小部件ButtonEditBox可以在测试文件中工作(下面提供的代码)但是当小工具在更大的应用程序中使用时会产生错误
self._apply_rule(child, crule, rootrule)
File "/usr/lib64/python2.7/site-packages/Kivy-1.8.0_dev-py2.7-linux-x86_64.egg/kivy/lang.py", line 1611, in _apply_rule
self._apply_rule(child, crule, rootrule)
File "/usr/lib64/python2.7/site-packages/Kivy-1.8.0_dev-py2.7-linux-x86_64.egg/kivy/lang.py", line 1608, in _apply_rule
child = cls(__no_builder=True)
File "/home/johan/workspace/Archery/misc.py", line 58, in __init__
super(ButtonEditBox, self).__init__(**kwargs)
TypeError: super(type, obj): obj must be an instance or subtype of type
小部件
from kivy.logger import Logger
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.stacklayout import StackLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
__all__ = ['ButtonEditBox']
class ButtonEditBox(BoxLayout):
label = ObjectProperty(0)
input = ObjectProperty(0)
on_text_validate = ObjectProperty(0)
#__events__ =('on_press')
def __init__(self, *args, **kwargs):
self.register_event_type('on_press')
#next line same as "/home/johan/workspace/Archery/misc.py", line 58
super(ButtonEditBox, self).__init__(**kwargs)
def set_label(self, name):
self.label.text = name
#self.update_callback()
def set_box(self, name):
self.input.text = name
def on_press(self):
print "on-pressed"
pass
def text_pressed(self):
print "text_pressed"
self.dispatch('on_press')
return True
Builder.load_string("""
<ButtonEditBox>:
input: input
label: label
height: self.input.height + self.label.height
id: layout1
orientation: 'horizontal'
Label:
text: 'Button 1'
id: label
size: len(self.text) * root.input.font_size, 2 * root.input.font_size
size_hint: None, None
TextInput:
id: input
text: 'Button 2'
multiline: False
size: root.width - root.label.width - root.spacing, 2 * self.font_size
size_hint: None, None
on_double_tap: root.text_pressed()
""")
if __name__ == '__main__':
from kivy.uix.popup import Popup
def update_game_name(instance, text=None):
if text != None:
print "To update text field: " + str(text)
app.input.text = text
else:
print "To show popup "
pop = Popup(content=ButtonEditBox(),
title='Change entry name'
)
pop.content.set_label('Entry name')
pop.content.set_box(app.input.text)
pop.bind(on_dismiss=lambda x: update_game_name(x, text=pop.content.input.text))
pop.size_hint = [.5, .5]
pop.open()
pass
app = ButtonEditBox()
class WidgetApp(App):
def build(self):
app.bind(on_press=update_game_name)
app.set_label("test name")
return app
WidgetApp().run()
Kivy使用旧的或新的python类吗?
如何解决给出的错误讯息?