有没有可能像我们在屏幕上切换一样打开一个带有某种转换的弹出窗口

2024-10-02 08:30:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我们可以在打开弹出窗口时添加任何转换吗。例如,当我们打开屏幕时 转换=FallOutTransition()。在弹出窗口的情况下也可以这样做吗。在

如果没有: 我正在考虑创建一个自定义弹出窗口,在那里我可以使用screen类并将其转换为transistion,但我无法理解它。有人知道吗?参见下面的示例代码:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen,FallOutTransition
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.popup import Popup
from kivy.uix.label import Label


class CPopup(Screen,Popup):
    def __init__(self, **kwargs):
        super(CPopup, self).__init__(**kwargs)
        self.transition= FallOutTransition()
        #self.title = "i am popup ... lol"

class A(Screen):
    def __init__(self, **kwargs):
        super(A, self).__init__(**kwargs)
        self.transition= FallOutTransition()
        self.add_widget(Label(text="I am label on the main Widget !"))
        popup = Popup(title="hello i am a simple Popup",content=Label(text="i am popup content"),size_hint=(None, None), size=(Window.height, Window.width/4))
        popup.open()
        popup.bind(on_open=self.on_open)

    def on_open(self,instance):
        print "hi popup was opened"
        Clock.schedule_once(instance.dismiss,2)


# App Class
class MyJBApp(App):
    def build(self):
        sm = ScreenManager(transition= FallOutTransition())
        sm.add_widget(A(name='A'))
        return sm

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

Tags: fromimportselfappinitondefopen
1条回答
网友
1楼 · 发布于 2024-10-02 08:30:17

Forexample when opening Screen we can have transition = FallOutTransition()

这是由屏幕管理器完成的,而不是屏幕。在

If not : I was thinking to create a Custom Popup where i can use screen Class and give transistion to it but i am not able to figure it out .

除非你用某种方式使用屏幕管理器,否则这是行不通的。在

你提到的FallOutTransition实际上使用了一个着色器效果,如果你不知道自己在做什么,那么在screenmanager之外很难复制这个效果(并不难,但也没有多少文档记录)。在

但是,使用普通的kivy动画可以获得几乎相同的效果。开始弹出窗口时,要比实际需要的小一些,并且不透明度为0,然后将其大小设置为实际需要的大小,将其不透明度设置为1。在

相关问题 更多 >

    热门问题