Created
November 20, 2012 22:20
-
-
Save pfeyz/4121646 to your computer and use it in GitHub Desktop.
wxPython Flickering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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