gpt4 book ai didi

python - 以编程方式在 Accordion 中切换 "tab"

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:34 29 4
gpt4 key购买 nike

我想在文件上按下“加载文件”按钮时切换“选项卡”,这意味着当加载文件时,它应该切换到第二个 AccordionItem。我如何以编程方式执行此操作?

 42     Accordion:                                                                  
43 orientation: 'horizontal'
44 anim_duration: 2
45
46 AccordionItem:
47 title: 'Load File'.title()
48 Page:
49 Header:
50 text: 'Load File'.title()
51 Body:
52 BoxLayout:
53 orientation: 'vertical'
54
55 FileChooser:
56 id: _filechooser
57 dirselect: False
58 multiselect: False
59 show_hidden: False
60 path: '~/'
61 filters: ['*.[Zz][Ii][Pp]', '*.[Xx][Mm][Ll]']
62 FileChooserIconLayout
63
64 Button:
65 height: '48dp'
66 size_hint_y: None
67 text: 'Load'.title()
68 on_release: root.load(_filechooser.path, _filechooser.selection)
69
70 Footer:
71 text: 'Choose file to load…'
72
73 AccordionItem:
74 title: 'Dmarc Report'.title()
75 Page:
76 Header:
77 text: 'Dmarc Report'.title()
78 Body:
79 Footer:
80 text: 'Viewing currently loaded file…'

最佳答案

您可以使用dispatch()方法来模拟点击AccordionItem:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string('''
<MyWidget>:
orientation: "vertical"
Button:
text: "switch"
size_hint: 1, 0.1
on_press:
if item1.collapse: item1.dispatch('on_touch_down', item1)
else: item2.dispatch('on_touch_down', item2)
Accordion:
AccordionItem:
id: item1
title: "1"
Label:
text: "1"
AccordionItem:
id: item2
title: "2"
Label:
text: "2"
''')


class MyWidget(BoxLayout):
pass

class MyApp(App):
def build(self):
return MyWidget()

if __name__ == '__main__':
MyApp().run()

关于python - 以编程方式在 Accordion 中切换 "tab",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37484027/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com