如上图所示,我想让我的苹果留在现场,并且复制的苹果变成了可翻转的物体。 哪种方式可行?
现在我的代码。
mn.py
from kivy.uix.widget import Widget
from kivy.uix.behaviors import DragBehavior
from kivy.app import App
from kivy.properties import StringProperty
class apple_0(DragBehavior,Widget):
def on_touch_move(self,touch):
return super(apple_0, self).on_touch_move(touch)
class apple_1(DragBehavior,Widget):
def on_touch_move(self,touch):
return super(apple_1, self).on_touch_move(touch)
class base_0(Widget):
def basepicture_0(self):
pass
class mn(Widget):
pass
class mnApp(App):
def build(self):
return mn()
if __name__=='__main__':
mnApp().run()
mn.kv
<mn>:
canvas:
Color:
rgb: 1,1,1,1
Rectangle:
size: root.width,root.height
pos: 0,0
Label:
pos: 30, root.top- 70
text:
('[size=20][color=000000]'
'fnc_slide_0'
'[/color][/0ize]')
markup: True
base_0:
id: base_0_id
pos: root.width/7, root.height/3
apple_0:
id: apple_0_id
pos: root.width/1.7,root.height/1.6
auto_bring_to_front: True
apple_1:
id: apple_1_id
pos: root.width/1.5,root.height/1.6
auto_bring_to_front: True
<base_0>
size: 944, 502
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'base_0.png'
<apple_0>:
size: 56.25,56.25
drag_rectangle: self.x, self.y, self.width, self.height
drag_timeout: 10000000
drag_distance: 0
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'apple_0.png'
<apple_1>:
size: 28.125,56.25
drag_rectangle: self.x, self.y, self.width, self.height
drag_timeout: 10000000
drag_distance: 0
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'apple_1.png'
答案 0 :(得分:1)
创建一个可点击的新窗口小部件,可以存储图像。如果需要,可以使用canvas
,但是我使用Image
,然后您可以在source
中传递__init__
。这样的小部件将具有接受位置和要生成的小部件类的功能。
单击生成器时,它会创建窗口小部件的新实例(因此参数中的类)并将其位置设置为生成器的位置。由于顶部的窗口小部件会捕获所有触摸,因此除非您移动窗口小部件或单击未覆盖的位置,否则不会再触发on_release
class Spawner(ButtonBehavior, Image):
def spawn(self, pos, widgetcls, *args):
widget_instance = widgetcls(pos=pos)
self.parent.add_widget(widget_instance)
通过你的苹果(如果你的苹果图像是圆形的边缘)。
仅编辑部分:
<强>的.py 强>
#:import Factory kivy.factory.Factory
<mn>:
canvas:
Color:
rgb: 1,1,1,1
Rectangle:
size: root.width,root.height
pos: 0,0
Label:
pos: 30, root.top- 70
text:
('[size=20][color=000000]'
'fnc_slide_0'
'[/color][/0ize]')
markup: True
base_0:
id: base_0_id
pos: root.width/7, root.height/3
Spawner:
id: apple_0_id
pos: root.width/1.7,root.height/1.6
on_release: self.spawn(self.pos, Factory.apple_0)
Spawner:
id: apple_1_id
pos: root.width/1.5,root.height/1.6
on_release: self.spawn(self.pos, Factory.apple_1)
<强> .kv 强>
kv
或者使用self.parent.add_widget(Factory.<widget>(pos=self.pos))
直接在X = pd.DataFrame(dict(age=[40., 50., 60.], sys_blood_pressure=[140.,150.,160.]))
print X
print type(X.as_matrix())# <type 'numpy.ndarray'>
print type(X.as_matrix()[0]) # <type 'numpy.ndarray'>
m = X.as_matrix()
m.dtype.names = list(X.columns)
中进行,但不太灵活。