我在kv文件中定义了一个基本的自定义DropDown。应用程序GUI非常简单,按钮栏位于顶部,TextInput消耗屏幕的其余部分。这是代码:
dropdowntrialgui.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.dropdown import DropDown
class CustomDropDown(DropDown):
pass
class DropDownTrialGUI(BoxLayout):
dropD = CustomDropDown()
def openMenu(self, widget):
self.dropD.open(widget)
class DropDownTrialGUIApp(App):
def build(self):
return DropDownTrialGUI()
if __name__== '__main__':
dbApp = DropDownTrialGUIApp()
dbApp.run()
和kv文件:
dropdowntrialgui.kv
DropDownTrialGUI:
<CustomDropDown>
Button:
text: 'My first Item'
size_hint_y: None
height: '28dp'
on_release: root.select('item1')
Button:
text: 'My second Item'
size_hint_y: None
height: '28dp'
on_release: root.select('item2')
<DropDownTrialGUI>:
orientation: "vertical"
padding: 10
spacing: 10
BoxLayout:
size_hint_y: None
height: "28dp"
Button:
id: toggleHistoryBtn
text: "History"
size_hint_x: 15
Button:
id: deleteBtn
text: "Delete"
size_hint_x: 15
Button:
id: replaceBtn
text: "Replace"
size_hint_x: 15
Button:
id: replayAllBtn
text: "Replay All"
size_hint_x: 15
Button:
id: menuBtn
text: "..."
size_hint_x: 15
on_press: root.openMenu(self)
TextInput:
id: readOnlyLog
size_hint_y: 1
readonly: True
按menuBtn无效。我该如何解决这个问题?