Kivy mapview-将按钮小部件放置在mapview小部件上方 [英] Kivy mapview - Place button widgets ontop of mapview widget
本文介绍了Kivy mapview-将按钮小部件放置在mapview小部件上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一些小部件添加到这样的Kivy地图视图中
I'm trying to add some widgets to a Kivy mapview like this
mapview = self.mapWidget(self.lat, self.lon)
touchBarbtn1 = Button(text='Unlock')
touchBarbtn1.bind(on_press=lambda x: self.centerOnUser())
mapview.add_widget(touchBarbtn1)
但是无论我提供什么布局选项,它始终卡在左下角.即使我添加了更多的小部件,它们也都堆叠在彼此的左下角.我的目标是在右上角创建一个按钮,以使地图居中显示用户.
But no matter what layout options I give it, it's always stuck in the bottom left corner. Even if I add more widgets they all just stack on top of each other in the bottom left corner. My Goal is to make a button on the top right corner to center the map on the user.
推荐答案
- Use Kivy Anchor Layout.
- If you are going to add more buttons, my suggestion is to use Kivy Drop-Down List.
示例
main.py
from kivy.garden.mapview import MapView
from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.button import Button
from kivy.properties import NumericProperty
class RootWidget(AnchorLayout):
lat = NumericProperty(50.6394)
lon = NumericProperty(3.057)
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
self.anchor_x = 'right'
self.anchor_y = 'top'
mapview = MapView(zoom=11, lat=self.lat, lon=self.lon)
self.add_widget(mapview)
touchBarbtn1 = Button(text='Unlock', size_hint=(0.1, 0.1))
touchBarbtn1.bind(on_press=lambda x: self.centerOnUser())
self.add_widget(touchBarbtn1)
def centerOnUser(self):
pass
class MapViewApp(App):
def build(self):
return RootWidget()
MapViewApp().run()
输出
这篇关于Kivy mapview-将按钮小部件放置在mapview小部件上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文