我有存储诊所,城市和诊所信息的数据库。当我在TextInput中输入城市名称时,会得到带有诊所名称的动态按钮列表。 (该列表是使用GridLayout和ScrollView创建的) 因此,我不知道该怎么做,因此当我单击带有诊所名称的按钮时,我会转到另一个屏幕,在该屏幕上可以看到有关该诊所的完整信息
这是我的main.py文件:
def on_start(self):
result_banner = self.root.ids['result_screen'].ids['result_banner']
con = psycopg2.connect(
host="localhost",
database="CLINICS",
user="postgres",
password="1922")
cur = con.cursor()
city = self.root.ids['home_screen'].ids.city.text
cur.execute("SELECT * FROM clinic WHERE city='%s'" %city)
rows = cur.fetchall()
self.root.ids['result_screen'].ids['result_banner'].clear_widgets()
for row in rows:
name_dict = {'name': row[1]}
adress_dict = {'adress': row[2]}
category_dict = {'category': row[4]}
website_dict = {'site': row[5]}
C = ClinicBanner(name=name_dict['name'])
result_banner.add_widget(C)
con.commit()
cur.close()
con.close()
这是我的ClinicBanner.py文件
class ClinicBanner(GridLayout):
rows = 1
def __init__(self, name,**kwargs):
super(ClinicBanner, self).__init__(**kwargs)
with self.canvas.before:
Color(rgb=(kivy.utils.get_color_from_hex("#ffffff")))
centre = FloatLayout()
centre_button = Button(text=name, size_hint=(2, 1), pos_hint={"top": .2, "left": .0001},
background_normal='',
background_color=kivy.utils.get_color_from_hex("#1854D6"),
on_release=self.ssc
)
centre.add_widget(centre_button)
self.add_widget(centre)