Skip to content

Instantly share code, notes, and snippets.

@antiface
Forked from pfeyz/lemon.png
Created August 6, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antiface/1b4d3c92a5f7ba9397e9c2e0fded1ec9 to your computer and use it in GitHub Desktop.
Save antiface/1b4d3c92a5f7ba9397e9c2e0fded1ec9 to your computer and use it in GitHub Desktop.
wxPython Flickering
import wx
class Fader(object):
def __init__(self, button):
self.button = button
self.val = 0
def fade(self, time=1000):
if self.val >= 255:
self.val = 0
return
else:
self.button.SetBackgroundColour(wx.Colour(self.val, self.val, self.val))
self.val += 10
wx.FutureCall(time / 50, lambda: self.fade(time))
def make_button(parent, image):
button = wx.BitmapButton(parent)
button.SetBitmapLabel(wx.Image(image).ConvertToBitmap())
return button
if __name__ == "__main__":
app = wx.App(False)
frame = wx.Frame(None)
button = make_button(frame, "lemon.png")
fader = Fader(button)
button.Bind(wx.EVT_BUTTON, lambda *x: fader.fade())
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment