Python Kivy在画布上有一个可点击的按钮
我试图让人们画一个时钟,当他们完成后,点击提交按钮,它将采取截图。当我使用画布绘制时,我不能再使用按钮 有没有办法将按钮放在画布顶部,使其仍然可以单击 main.pyPython Kivy在画布上有一个可点击的按钮,python,python-3.x,canvas,kivy,kivy-language,Python,Python 3.x,Canvas,Kivy,Kivy Language,我试图让人们画一个时钟,当他们完成后,点击提交按钮,它将采取截图。当我使用画布绘制时,我不能再使用按钮 有没有办法将按钮放在画布顶部,使其仍然可以单击 main.py class Clock(Screen): def on_touch_down(self, touch): print(touch) with self.canvas.before: touch.ud["line"] = Line(points = (touch.x,
class Clock(Screen):
def on_touch_down(self, touch):
print(touch)
with self.canvas.before:
touch.ud["line"] = Line(points = (touch.x, touch.y), width = 2)
def on_touch_move(self, touch):
print(touch)
touch.ud["line"].points += (touch.x, touch.y)
def on_touch_up(self, touch):
print("released", touch)
时钟千伏
#:import utils kivy.utils
<Clock>:
FloatLayout
canvas.before:
Color:
rgba: .5, .5, .5, .5
Line:
width: 50
rectangle: self.x, self.y, self.width, self.height
Label:
pos_hint: {"top": .9, "center_x": .5}
size_hint: 1, .1
text: "Draw a clock."
font_size: 25
BoxLayout:
id: myexport
Button:
pos_hint: {"top": .1, "right": 1}
size_hint: .1, .1
text:
"Submit"
on_release:
app.change_screen("animals1")
myexport.export_to_png("Clock.png")
:导入utils kivy.utils
:
浮动布局
在以下情况之前:
颜色:
rgba:.5、.5、.5、.5
行:
宽度:50
矩形:self.x、self.y、self.width、self.height
标签:
pos_提示:{“top”:.9,“center_x”:.5}
大小提示:1、.1
课文:“画一个时钟。”
字体大小:25
盒子布局:
id:myexport
按钮:
pos_提示:{“top”:.1,“right”:1}
大小提示:.1,.1
正文:
“提交”
发布时:
应用程序更改屏幕(“动物1”)
myexport.export_到_png(“Clock.png”)
在时钟
类方法中,您需要调用超级
方法以正确传播事件:
class Clock(Screen):
def on_touch_down(self, touch):
print(touch)
with self.canvas.before:
touch.ud["line"] = Line(points = (touch.x, touch.y), width = 2)
return super(Clock, self).on_touch_down(touch)
def on_touch_move(self, touch):
print(touch)
touch.ud["line"].points += (touch.x, touch.y)
return super(Clock, self).on_touch_move(touch)
def on_touch_up(self, touch):
print("released", touch)
return super(Clock, self).on_touch_up(touch)