【发布时间】:2017-09-18 02:15:37
【问题描述】:
我在 Kivy 中创建了一个带有 6 个切换按钮的主窗口。 我喜欢通过每个切换按钮上的长按事件来访问具有相关设置的弹出窗口。
弹出窗口已定义,并具有“下一个”和“上一个”按钮,可从一个设置页面循环到下一个设置页面。
如何避免在 Kivy 中手动创建这些弹出定义?
虚拟 .kv 代码:
#:import Factory kivy.factory.Factory
<MyPopup2@Popup>:
auto_dismiss: False
title: "Popup Window No. 2"
Button:
text: 'Close me, too!'
on_release: root.dismiss()
MyPopup1@Popup:
auto_dismiss: False
size_hint: None,None
size: 400,300
title: "Popup Window No. 1"
BoxLayout:
orientation: "vertical"
BoxLayout:
orientation: "vertical"
BoxLayout:
Label:
text: 'Circuit Active:'
Switch:
id: "switch1"
BoxLayout:
Label:
text: 'Default Watering Time: [min]'
TextInput:
text: '30'
BoxLayout:
Label:
text: 'Watering Group'
TextInput:
text: '3'
BoxLayout:
Button:
text: 'Previous'
Button:
text: 'Cancel'
on_release: root.dismiss()
Button:
text: 'Save + Exit'
Button:
text: 'Next'
on_release: root.dismiss()
on_release: Factory.MyPopup2().open()
BoxLayout:
orientation: "vertical"
padding: 5
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 1"
# disabled: True
on_release: Factory.MyPopup1().open()
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 2"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 3"
BoxLayout:
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 4"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 5"
BoxLayout:
padding: 5
ToggleButton:
text: "Wasserkreis 6"
BoxLayout:
BoxLayout:
padding: 5
Label:
text: 'Drei Zeilen\nmit\nStatusmeldungen'
BoxLayout:
size_hint_x: 0.5
padding: 5
ToggleButton:
text: "Automatik-\nBetrieb"
on_press: app.testfunktion()
【问题讨论】:
-
您是否要为其余五个按钮重复 MyPopup1 和 MyPopup2?
-
是的,正确的。我喜欢为六个花园浇水阀设置 6 个相同的设置弹出窗口,并且我希望有“下一个”和“上一个”按钮从一个弹出窗口转到另一个,而无需关闭并通过主屏幕。
标签: python kivy popupwindow