Итак, я использую Kivy, чтобы создать базовое имя и средство записи заметок (как таковое досье) с помощью Python. Мне любопытно, как можно щелкнуть имя и получить дополнительную информацию (заметки о человеке). Я видел функцию CustomPopup (), но она кажется более специфичной для заданного элемента, тогда как я хотел бы иметь возможность щелкнуть любое имя и сделать заметки видимыми. Просто указать в правильном направлении было бы здорово, спасибо.
И вот часть кода. Я новичок в программировании, поэтому он в значительной степени взят из Дерека Банаса, чтобы удовлетворить мои текущие потребности.
Сторона 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()






Используйте RecycleView имен. При щелчке по любому имени заполните содержимое виджета Popup заметками об этом человеке.
Deprecated since version 1.10.0: ListView has been deprecated, use RecycleView instead.