【问题标题】:In wxpython, how can I drag a frame while having it play a GIF animation在 wxpython 中,如何在播放 GIF 动画的同时拖动帧
【发布时间】:2016-08-29 05:29:01
【问题描述】:

我正在为此使用 wxpython-Phoenix 3.0.3 版本。

我想制作一个播放 GIF 动画的可拖动图像。 当我注释掉动画部分时,该功能工作正常,但在播放动画时它不起作用。 我怎样才能让它们一起工作?

import wx
from wx.adv import AnimationCtrl


class Yukari(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, -1, title)

        self.Bind(wx.EVT_MOTION, self.OnMouse)
        self.Bind(wx.EVT_CHAR_HOOK, self.closeWindow)

        self.animation = AnimationCtrl(self)
        self.animation.LoadFile('Resized_Yuzuki-Yukari.gif')
        self.animation.Play()

        self.SetSize((497, 720))
        self.SetWindowStyle(wx.SIMPLE_BORDER | wx.STAY_ON_TOP)
        self.Show()

    def OnMouse(self, event):

        if not event.Dragging():
            self._dragPos = None
            pass
        if not self._dragPos:
            self._dragPos = event.GetPosition()
        else:
            pos = event.GetPosition()
            displacement = self._dragPos - pos
            print(displacement)
            self.SetPosition(self.GetPosition() - displacement)

    def closeWindow(self, event):
        key_code = event.GetKeyCode()
        if key_code == wx.WXK_ESCAPE:
            self.Destroy()
        event.Skip()


app = wx.App()
frame = Yukari(None, -1, 'Yuzuki Yukari')
app.MainLoop()

【问题讨论】:

    标签: animation wxpython draggable gif


    【解决方案1】:

    这适用于 Linux mate 17、python 2.7、wx.python ('2.8.12.1 (gtk2-unicode)',使用 from wx.animate import AnimationCtrl
    当您说“但是在播放动画时它不起作用”时,它不起作用的方式是什么,当您说“可拖动图像”时,您的意思是该图像在帧内是“可拖动的”还是该帧可以拖动吗?
    另外,我相信您需要将项目放在 wx.panel() 之类的东西中才能激活事件动作,即

    self.panel1 = wx.Panel(self)
    self.panel1.Bind(wx.EVT_MOTION, self.OnMouse)
    self.panel1.Bind(wx.EVT_CHAR_HOOK, self.closeWindow)
    
    self.animation = AnimationCtrl(self.panel1)
    

    【讨论】:

    • 首先,感谢您的回答。不幸的是,“wx.animate import AnimationCtrl”不适用于 Phoenix 版本。我对可拖动图像的意思是,框架本身是不可拖动的。是的,我会尝试使用面板而不是框架感谢您的建议!
    猜你喜欢
    • 2014-06-16
    • 1970-01-01
    • 2012-03-23
    • 2021-07-21
    • 2012-08-24
    • 2021-10-15
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多