The idea of this thread is to help the beginning wxPython GUI programmer with hints and helpful code. Please feel free to contribute! If you have any questions start your own thread! For info on wxPython modules see: http://www.wxpython.org/docs/api/wx-module.html
sneekula
Nearly a Posting Maven
2,483 posts since Oct 2006
Reputation Points: 1,000
Solved Threads: 231
Skill Endorsements: 2
Yes, project Phoenix does rewrite all the wxPython code to make it work with Python2 and Python3.
For old time sake, some fun with colors:
# color a wxPython panel every 2.5 seconds with a random color
import wx
import random
from wx.lib.colourdb import *
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(600, 450))
self.panel = wx.Panel(self, -1)
# create a list of wx colors (from wx.lib.colourdb)
self.colors = getColourList()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
# milliseconds
self.timer.Start(2500)
self.Center()
def OnTimer(self, event):
self.panel.SetBackgroundColour(wx.RED)
# pick a random color from the list
color = random.choice(self.colors)
self.panel.SetBackgroundColour(color)
self.panel.Refresh()
self.SetTitle(color)
app = wx.App(0)
# contains all the wx color names (from wx.lib.colourdb)
updateColourDB()
# create the frame instance
frame = MyFrame(None, -1, 'randomcolours.py')
frame.Show(True)
app.SetTopWindow(frame)
app.MainLoop()
Lardmeister
Posting Virtuoso
1,939 posts since Mar 2007
Reputation Points: 465
Solved Threads: 72
Skill Endorsements: 5