如何在kivy python中正确使用radiobutton?
How to use radiobutton correctly in kivy python?
我正在使用单选按钮小部件。我希望复选框始终位于单选按钮之一上,这意味着它不能被永久删除。请告诉我该怎么做。这是我的代码片段:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.checkbox import CheckBox
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)
class BooruScraperApp(App):
def build(self):
choose_box = BoxLayout()
first_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0], active = True)
second_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0])
third_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0])
choose_box.add_widget(first_check)
choose_box.add_widget(second_check)
choose_box.add_widget(third_check)
return choose_box
if __name__ == '__main__':
BooruScraperApp().run()
您可以使用 allow_no_selection 属性:
first_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], active=True, allow_no_selection=False)
second_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], allow_no_selection=False)
third_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], allow_no_selection=False)
我正在使用单选按钮小部件。我希望复选框始终位于单选按钮之一上,这意味着它不能被永久删除。请告诉我该怎么做。这是我的代码片段:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.checkbox import CheckBox
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)
class BooruScraperApp(App):
def build(self):
choose_box = BoxLayout()
first_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0], active = True)
second_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0])
third_check = CheckBox(group = 'test', size_hint_x = .047, size_hint_y = .047, color = [0, 0, 0])
choose_box.add_widget(first_check)
choose_box.add_widget(second_check)
choose_box.add_widget(third_check)
return choose_box
if __name__ == '__main__':
BooruScraperApp().run()
您可以使用 allow_no_selection 属性:
first_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], active=True, allow_no_selection=False)
second_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], allow_no_selection=False)
third_check = CheckBox(group='test', size_hint_x=.047, size_hint_y=.047, color=[0, 0, 0], allow_no_selection=False)