这是我创建的虚拟循环程序,它应该创建一个按钮,单击按钮应该创建一个具有相同名称的新按钮。
单击第二个按钮后失败,事件不再传递实例对象。
self.frame指的是.kv文件
第一个文件
#run.py
import view
class UserInterface(BoxLayout):
self.V = view.View()
def callback(self, instance):
print "Instance Object: ", instance
if instance.id == "Home":
activeView = self.V.home()
# Clear children before instating new view
self.frame.clear_widgets()
self.frame.add_widget(activeView)
第二档
#view.py
from run import UserInterface
class View():
def home(self):
nav_panel = BoxLayout(orientation= "vertical", id="navPanel")
btn = Button(text="Normal binding to event", id="Home")
btn.bind(on_press=UserInterface.callback)
nav_panel.add_widget(btn)
return btn
Instance Object: <kivy.uix.button.Button object at 0x709fac00>
Traceback (most recent call last):
...
TypeError: callback() takes exactly 2 arguments (1 given)
1个参数是&#34; self&#34; 你能看出我做错了吗?