我正在尝试仅使用纯python在kivy中创建搜索栏。通过选择单选按钮
有什么方法可以将某个字符串返回给函数这是我程序中的一小段。如果您可以使用纯python代码回答
class avbl_bk(Screen):
def __init__(self,**kwargs):
super(avbl_bk,self).__init__(**kwargs)
blayout=BoxLayout(orientation="vertical")
check=BoxLayout()
search_layout=BoxLayout(spacing=10,padding=5)
search_label=Label(text="Search: ",size_hint_x=0.5)
search_box=TextInput(multiline=False,font_size=40,size_hint_x=0.8)
search=Button(text="Search",size_hint=(.3,0.8))
chk1=CheckBox(group='1')
chk2=CheckBox(group='1')
chk3=CheckBox(group='1')
chk4=CheckBox(group='1')
chk5=CheckBox(group='1')
chk6=CheckBox(group='1')
filters=["ISBN","Book","Genre","Author","Publisher","Copies"]
for i in range(6):
check.add_widget(Label(text=filters[i]))
check.add_widget(eval(("chk"+str(i+1))))
search_layout.add_widget(search_label)
search_layout.add_widget(search_box)
search_layout.add_widget(check)
search_layout.add_widget(search)
blayout.add_widget(search_layout)
self.add_widget(blayout)
答案 0 :(得分:0)
我想使用字符串在数据库中执行查询, 当我按下搜索按钮时显示它。那我该怎么办?
StringProperty
类型的search_by
App.get_running_app()
函数访问应用实例search_type
方法中的instance.text
填充on_active()
search_by
class CustomCheckBox(CheckBox):
text = StringProperty('')
def on_active(self, instance, value):
if value:
print(f'\tThe checkbox text={instance.text} is active')
App.get_running_app().root.search_by = instance.text
class avbl_bk(Screen):
search_by = StringProperty('')
def __init__(self, **kwargs):
super(avbl_bk, self).__init__(**kwargs)
...
有什么方法可以将某个字符串从 选择一个单选按钮
解决方法如下:
class CustomCheckBox
小部件的CheckBox
text
的{{1}} StringProperty
事件on_active
循环内用CustomCheckBox
和group='1'
实例化text=text=filters[i]
for