我基本上是想补充kivy.garden.mapview公司作为kivy应用程序的小部件。在
我就是这么想的。在
我还添加了Painter类,因为如果我使用Painter作为小部件,它可以完美地工作,但是Map类则不行。 另外,Map if作为一个应用程序测试时返回的mapview非常好用。在
from kivy.app import App
# kivy.require("1.10.1")
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.garden.mapview import MapView,MapMarker
from kivy.uix.widget import Widget
from kivy.graphics import Line
xList = [3.2,4]
yList = [2.3,3]
class Map(Widget):
def on_touch_down(self, touch):
global xList
global yList
mapview = MapView(zoom=1, lat=67, lon=42)
m1 = MapMarker(lat=67, lon=42)
mapview.add_marker(m1)
print(xList)
print(yList)
for i in range(len(xList)):
m=MapMarker(lat=xList[i],lon=yList[i])
mapview.add_marker(m)
# return mapview
class Painter(Widget):
def on_touch_down(self, touch):
with self.canvas:
touch.ud["line"] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
touch.ud["line"].points += [touch.x, touch.y]
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("SimpleKivy.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
kivy档案是
^{pr2}$那我该怎么做呢?在
我可以不让地图成为一个小部件吗?在
我需要一个图表,所以我需要至少有2个屏幕。在
实际上,您没有将
MapView
添加到App
中。您可以在您的Map
小部件中引用它,但永远不会将其添加到App
中。一种方法是将Map
更改为扩展MapView
:在
^{pr2}$kv
文件中,添加Map
的初始设置:相关问题 更多 >
编程相关推荐