我试图在“脚本”事件类中的变量“current_text”时更新“EventWindow”中标签的文本/事件.py”. 我知道答案可能在于将“current”绑定到“ct”,但这只会导致“AttributeError:class Event没有属性‘bind’”。如果我用这个方法找错了方向,我会很乐意接受另一种方法。在
下面是相关的代码片段,但是完整的项目可以在:https://github.com/DinkWerks
from kivy.properties import ObjectProperty, StringProperty
from kivy.app import App
# Utility Imports
import yaml
# Game Imports
from scripts.events import Event
# File Loads
loc_file = file('data/location.yml')
loc_dat = yaml.load(loc_file)
# Bind Classes
event = Event()
class EventWindow(BoxLayout):
ct = StringProperty('')
def __init__(self, **kwargs):
super(EventWindow, self).__init__(**kwargs)
self.ct = event.current_text
# Error occurs below. Comment out too see semi-functional app.
Event.bind(current_text=self.setter('ct'))
<EventWindow>:
BoxLayout:
pos: 100,100
size_hint: .4,.7
orientation: 'vertical'
Image:
source: 'maps/map.jpg'
pos: self.pos
size: self.size
ScrollView:
canvas.before:
Color:
rgba: [.2,.2,.2,.8]
Rectangle:
size: self.size
pos: self.pos
Label:
id: text_area
text: root.ct
padding: 15,10
text_size: self.width, None
size_hint_y: None
height: self.texture_size[1]
<Foo>:
id: bl
popup: popup.__self__
header: header
BoxLayout:
orientation: 'vertical'
BoxLayout:
...
FloatLayout:
id: mapspace
canvas:
...
EventWindow:
id: event
Popup:
...
谢谢!在
在您的代码中,} )。很可能只要使
Event
是从Player
派生的,它本身就是一个old style class。重要的是,它们都没有实现事件管理所需的方法(例如,fbind
;对于定义接口的存根类,请参见^{Event
或Player
成为{a3}的子类,就可以创建并绑定到事件kivy样式。在相关问题 更多 >
编程相关推荐