Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Kivy widget在某些情况下给出类型错误_Python_Inheritance_Kivy - Fatal编程技术网

Python Kivy widget在某些情况下给出类型错误

Python Kivy widget在某些情况下给出类型错误,python,inheritance,kivy,Python,Inheritance,Kivy,我有一个widget ButtonEditBox,它在测试文件中工作(下面提供的代码),但是当widget在更大的应用程序中使用时,就会产生错误 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

我有一个widget ButtonEditBox,它在测试文件中工作(下面提供的代码),但是当widget在更大的应用程序中使用时,就会产生错误

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.logger导入记录器
从kivy.app导入应用程序
从kivy.uix.boxlayout导入boxlayout
从kivy.uix.label导入标签
从kivy.lang导入生成器
从kivy.uix.textinput导入textinput
从kivy.uix.stacklayout导入stacklayout
从kivy.uix.button导入按钮
从kivy.uix.gridlayout导入gridlayout
从kivy.properties导入ObjectProperty
从kivy.uix.widget导入widget
__全部u u=['ButtonEditBox']
类按钮编辑框(框布局):
label=ObjectProperty(0)
输入=对象属性(0)
在\u text\u validate=ObjectProperty(0)上
#__事件=('on_press')
定义初始化(self,*args,**kwargs):
self.register\u事件类型('on\u press')
#下一行与“/home/johan/workspace/Archery/misc.py”第58行相同
超级(按钮编辑框,自我)。\uuuuuu初始化(**kwargs)
def set_标签(自身、名称):
self.label.text=名称
#self.update_callback()
def设置_框(自身,名称):
self.input.text=名称
def on_按下(自):
打印“按上”
通过
按def text_键(自身):
打印“已按文本”
自动发送('在印刷机上')
返回真值
生成器。加载\u字符串(“”)
:
输入:输入
标签:标签
高度:self.input.height+self.label.height
id:布局1
方向:“水平”
标签:
文本:“按钮1”
id:标签
大小:len(self.text)*root.input.font\u size,2*root.input.font\u size
大小提示:无,无
文本输入:
id:输入
文本:“按钮2”
多行:False
大小:root.width-root.label.width-root.space,2*self.font\u大小
大小提示:无,无
双击:root.text\u按下()
""")
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
从kivy.uix.popup导入弹出窗口
def更新游戏名称(实例,文本=无):
如果文本!=无:
打印“以更新文本字段:”+str(文本)
app.input.text=文本
其他:
打印“显示弹出窗口”
弹出=弹出(内容=按钮编辑框(),
title='Change entry name'
)
pop.content.set_标签('条目名称')
pop.content.set_框(app.input.text)
绑定(on_discouse=lambda x:update_game_name(x,text=pop.content.input.text))
pop.size_hint=[0.5,5]
pop.open()
通过
app=按钮编辑框()
WidgetApp类(应用程序):
def生成(自):
应用程序绑定(按=更新游戏名称)
应用程序设置标签(“测试名称”)
返回应用程序
WidgetApp().run()
Kivy使用旧的还是新的python类


如何解决给出的错误消息?

我不知道是什么原因造成的,我觉得这很好。是否有可能在较大的项目中定义了其他具有相同名称的类?我没有找到任何具有相同名称的其他类。较大的项目是为文件重建文件。包含来自misc import*的文件时,错误再次出现;进口杂项;重新加载(杂项)。删除最后两条语句后,错误消失。