0
使用Kivy ActionBar,我已經成功創建了一個搜索小部件。唯一的問題是,添加搜索輸入後,ActionBar中留有大量空餘空間。搜索功能在ActionBar中調整大小Kivy Python 3
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
Builder.load_string("""
<RootWidget>:
ActionBar:
background_color: .5, .7, .6, 1
size_hint_y: .10
pos_hint: {'top':1}
ActionView:
ActionPrevious:
with_previous: False
SearchBar:
size_hint_x: 1
size_hint_y: .5
pos_hint: {'x': 0, 'center_y':.5}
on_text_validate: searchbutt.trigger_action()
ActionButton:
icon: "search.png"
size_hint_x: None
size_hint_y: None
size: (30,30)
pos_hint: {'x': .3, 'center_y': .5}
id: searchbutt
ActionOverflow:
ActionButton:
text: 'Btn1'
ActionButton:
text: 'Btn2'
ActionButton:
text: 'Btn3'
""")
class RootWidget(BoxLayout):
def __init__(self, *args, **kwargs):
super(RootWidget, self).__init__(*args, **kwargs)
pass
class SearchBar(TextInput, ActionItem):
def __init__(self, *args, **kwargs):
super(SearchBar, self).__init__(*args, **kwargs)
self.hint_text='Enter Location'
def search(self):
request = self.text
return str(request)
class VerticalPanes(BoxLayout):
orientation= 'vertical'
pass
class HorizontalPanes(BoxLayout):
pass
class EventScreen(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
EventScreen().run()
這裏是我的文件中的代碼,如果你運行它,並調整窗口的大小,那麼你可以在搜索欄縮小,直到它幾乎是無用的,但下面的應用程序圖標空的空間充足。另外,如果你看到任何通用的部分,我可以改進我的代碼/技術,lemme知道。
PS:search.png只是一個放大鏡圖標