简体   繁体   English

如何将画布添加到布局(python kivy)

[英]how to add canvas to Layout(python kivy)

I want to add some canvas to Layout, but when I launch this small code it writes "black" screen... 我想在“布局”中添加一些画布,但是当我启动这个小代码时,它会写成“黑色”屏幕...

I use kivy 1.10 and python 3.6.4 我使用kivy 1.10和python 3.6.4

Can anyone help me ? 谁能帮我 ?

following code : 以下代码:

from kivy.app import App
from kivy.graphics import Color,Bezier
from kivy.uix.anchorlayout import AnchorLayout

class AncLayout(AnchorLayout):  
    with AnchorLayout().canvas:
        Color(.1,.88,.71,.57)
        Bezier(points = (100,100,70,70,40,70,100,100),    
               segments = 120,
               dash_length = 9,
               dash_offset = 3)

class MasterApp(App):
    def build(self):
        return AncLayout()  


if __name__ == '__main__':
    MasterApp().run()

Great thanks for any help ) 非常感谢您的帮助)

The problem is that you are adding the curves to an AnchorLayout that you have created and you have not added to your application, the next line with AnchorLayout().canvas creates a new Anchorlayout . 问题是您AnchorLayout曲线添加到已创建的AnchorLayout ,但尚未添加到应用程序中,因此,下一行带有AnchorLayout().canvasAnchorlayout创建一个新的Anchorlayout You must do this task in the constructor: 您必须在构造函数中执行以下任务:

from kivy.app import App
from kivy.graphics import Color,Bezier
from kivy.uix.anchorlayout import AnchorLayout

class AncLayout(AnchorLayout):
    def __init__(self, *args, **kwargs):
        AnchorLayout.__init__(self, *args, **kwargs)
        with self.canvas:
            Color(.1,.88,.71,.57)
            Bezier(points = (100,100,70,70,40,70,100,100),    
                   segments = 120,
                   dash_length = 9,
                   dash_offset = 3)

class MasterApp(App):
    def build(self):
        return AncLayout()  


if __name__ == '__main__':
    MasterApp().run()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM