![]() |
|---|
| © dotmodus |
由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

Quick Start
By copy the codes from the document, you are supposed being able to show the line on the screen and adjust the alpha, width, etc of the line.
ListProperty([(500, 500),[300, 300, 500, 300],[500, 400, 600, 400]])
As you can see above, you can envelope the points by () or [], you can line the points one by one or line them all together if you wish (The examples show down below).
ListProperty([(500, 500),[300, 300], [500, 300],[500, 400], [600, 400]])```pythonor```pythonListProperty([500, 500, 300, 300, 500, 300, 500, 400, 600, 400])
The minimal codes you’ve to keep is:
from kivy.app import Appfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.lang import BuilderBuilder.load_string('''<LinePlayground>:# assign a list variate as point so it could be easliy handled in laterpoint: [0,0, 200, 100]canvas:Color:rgba: .4, .4, 1, 1Line:# recall the variate 'point' abovepoints: self.point''')class LinePlayground(FloatLayout):passclass TestLineApp(App):def build(self):return LinePlayground()if __name__ == '__main__':TestLineApp().run()
updating the line
If you are not satisfied with drawing a line and want to create an animation, than like do some thing cool.
updating….
from kivy.app import Appfrom kivy.properties import ListPropertyfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.uix.widget import Widgetfrom kivy.lang import Builderfrom kivy.clock import Clockfrom kivy.properties import ObjectProperty## Remove unnecessary codes from this classclass LinePlayground(FloatLayout):passclass Main_app(Widget):# assign a numeric variatei = 0# connect the class in kv file: line -> line_ground -> LinePlaygroundline = ObjectProperty(None)def update(self, dt):self.i +=1# update the pointself.line.point = [[0,0,], [self.i,self.i]]print(self.line.point)print(self.line)print("1")class TestLineApp(App):def build(self):Main = Main_app()# update the result with 60 fps (1/60)Clock.schedule_interval(Main.update,1/60)return Mainif __name__ == '__main__':TestLineApp().run()
testline.kv file:
<LinePlayground>:# assign a list variate as point so it could be easliy handled in laterpoint: [0,0, 200, 100]canvas:Color:rgba: .4, .4, 1, 1Line:# recall the variate 'point' abovepoints: self.point<Main_app>:# assign the id which could be recall laterline: line_groundLinePlayground:id: line_groundpoint: [0,10, 100,200]

Enjoy~
由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址
GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗

