【发布时间】:2017-02-25 16:57:08
【问题描述】:
在 kivy 中实现弹出窗口的方式,弹出窗口似乎附加到窗口而不是创建弹出窗口的父对象。弹出窗口带有 self.dismiss() 来关闭弹出窗口,但我无法找到访问“父”对象的任何方法,因为尽管创建了弹出窗口,但它似乎存在于它之外。
示例 sn-ps:
class StartButton(ActionButton)
def on_release(self):
self.popup = StartPop(id='popid')
self.popup.open()
class StartPop(Popup):
def close(self):
self.dismiss()
def start(self):
print(self)
print(self.parent)
打印命令的结果是
<__main__.StartPop object at 0x00000000037BBCE0>
<kivy.core.window.window_sdl2.WindowSDL object at 0x000000000373B0B0>
因此,与其父级是 StartButton,我还希望访问其父级等。父级是 Window。
我不知道如何绑定任何与我用来创建弹出窗口的小部件交互的函数。我需要能够让父对象及其父对象根据我在弹出窗口中单击的内容来执行操作,但我不知道如何实现。
在.kv文件中
<StartPop>:
title: 'Popup'
auto_dismiss: True
size_hint: None,None
size: 400,250
BoxLayout:
orientation: 'vertical'
Label:
text: 'sample text here'
text_size: self.size
halign: 'center'
valign: 'middle'
BoxLayout:
orientation: 'horizontal'
Button:
size_hint: 1,0.5
text: 'Cancel'
on_release: root.close()
Button:
size_hint: 1,0.5
text: 'Start Testing'
on_release: root.start()
【问题讨论】:
标签: python python-2.7 popup kivy