所以我正在使用Kivy用Python构建一个基本名称和注释器(本身的一个档案)。我很好奇如何能够点击名称并提供更多信息(关于此人的注释)。我看到了CustomPopup()功能,但这似乎更具体到一个设置项,而我希望能够点击任何名称并让注释可见。只是朝着正确方向迈出了一步,谢谢你。
这里有一些代码,我对编程非常陌生,所以这几乎是从Derek Banas中剔除,以满足我目前的需求。
Python方面:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.listview import ListItemButton
from kivy.uix.popup import Popup
class HumanListButton(ListItemButton):
pass
class CustomPopup(Popup):
pass
class HumanDB(BoxLayout):
first_name_text_input = ObjectProperty()
last_name_text_input = ObjectProperty()
notes_input = ObjectProperty()
human_list = ObjectProperty()
def submit_human(self):
# get the human name from textinput, synatx is to use varriable of the textinput.text
human_name = self.first_name_text_input.text + " " + self.last_name_text_input.text + " Notes: " + self.notes_input.text
# add to list view
self.human_list.adapter.data.extend([human_name])
# reset the listview, this makes sure it gets updated
self.human_list._trigger_reset_populate()
def delete_human(self):
# this is where banas talks about building a database
# if a list item is selected
if self.human_list.adapter.selection:
# get the text from the item selected
selection = self.human_list.adapter.selection[0].text
# remove the matching human
self.human_list.adapter.data.remove(selection)
# reset the listview
self.human_list._trigger_reset_populate()
def replace_human(self):
# if a list item is selected
if self.human_list.adapter.selection:
# get the human name from textinput
selection = self.human_list.adapter.selection[0].text
# remove matching item
self.human_list.adapter.data.remove(selection)
# get the huamn name from TextInputs
human_name = self.first_name_text_input.text + " " + self.last_name_text_input.text + " Notes: " + self.notes_input.text
# add the updated data to the list
self.human_list.adapter.data.extend([human_name])
# reset the listview
self.human_list._trigger_reset_populate()
def open_popup(self):
the_popup = CustomPopup()
the_popup.open()
class HumanDBApp(App):
def build(self):
return HumanDB()
dbApp = HumanDBApp()
dbApp.run()
答案 0 :(得分:0)
使用名称的RecycleView。单击任何名称时,使用该人员的注释填充Popup小部件的内容。
自版本1.10.0后不推荐使用:ListView已被弃用,请使用 而是RecycleView。