我正在尝试使用kivy绘制各种线段。该线看起来很小(在屏幕的一端),我想扩大它。理想情况下,我想从屏幕中心指定坐标并指定宽度和高度,以便线段显示良好。这是我写的代码:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.graphics import Color, Ellipse, Line
class MyWidget(Widget):
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
with self.canvas:
for obstacle in obstacles:
print obstacle
Line(points=[20, 5, 40, 5],width=1)
pass
# add your instruction for main canvas here
class MotionPlanningApp(App):
def build(self):
root = GridLayout(cols=1, padding=5, spacing=1)
root.add_widget(MyWidget())
return root
if __name__ == '__main__':
MotionPlanningApp().run()
在kivy有没有办法做到这一点?
答案 0 :(得分:0)
您可以使用翻译说明移动线条(有效移动画布的原点)和缩放说明以拉伸它。
例如,您可以:
from kivy.core.window import Window
with self.canvas:
self.translate = Translate(Window.width / 2, Window.height / 2.)
如果窗口大小发生变化,您还需要通过将函数绑定到该窗口来修改转换指令。
但是,无论如何,坐标都是屏幕像素,所以线条目前很小,因为你只有20像素长。