[wxPython-users] Newbie has a statusbar problem
Giuseppe Costanzi
g.costanzi at idi.it
Sun Nov 4 01:58:23 PDT 2007
Regan Tackett ha scritto:
> In the code below, I have created a panel with 2 radio buttons on it. Wh=
en I
> click and activate "Button 2", I would like to have a certain message app=
ear on
> the status bar. However, when the code is run, the message appears at th=
e top
> of the panel. I think my problem is that I'm setting the panel that I cr=
eated
> as the parent of the statusbar. However, I don't know (or have I ever sa=
w an
> example) how to pass the frame instance to the panel. Could some of you =
more
> experienced programmers tell me where I've went wrong? Below is the code=
. I
> tried to make it as simple as possible.
> =
> Hi Regan,
>
> I've attached a little demo.
>
> My demo doesn't use so many class like your but I think you like it.
> I've use wx.RadioBox insted RadioButton but I think it's the same thing
> =
Giuseppe
Python-it.org
-------------- next part --------------
#!/usr/bin/env python
import wx
import time
#checkbox.py
#web Python-it.org
AppTitle =3D 'Python-it.org'
class Main_Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, '',size=3D(600,400))
#self.SetIcon(wx.Icon("MyIcon.ico",wx.BITMAP_TYPE_ICO))
self.SetTitle(AppTitle)
=
=
self.Bind(wx.EVT_CLOSE, self.OnExit)
=
panel =3D wx.Panel(self)
#Statusbar
self.myStatusBar =3D self.CreateStatusBar(1,wx.ST_SIZEGRIP) =
self.myStatusBar.SetFieldsCount(2) =
self.myStatusBar.SetStatusWidths([-8, -4]) =
self.myStatusBar.SetStatusText('Python-it.org',1)
#Clock
self.OnTimer(None)
self.timer =3D wx.Timer(self)
self.timer.Start(1000)
self.Bind(wx.EVT_TIMER, self.OnTimer)
#widgets
self.opType =3D ['A', 'B','C','D']
self.rbChoice =3D wx.RadioBox(
panel, -1, "Choice", wx.DefaultPosition, wx.DefaultSize,
self.opType,0, wx.RA_SPECIFY_COLS
)
self.rbChoice.Bind(wx.EVT_RADIOBOX, self.OnRadio, self.rbChoice) =
=
#Sizers
mainSizer =3D wx.BoxSizer(wx.HORIZONTAL)
radSizer =3D wx.BoxSizer(wx.VERTICAL)
radSizer.Add(self.rbChoice, 0)
=
mainSizer.Add(radSizer, 0,wx.ALL, 10)
panel.SetSizer(mainSizer)
self.Center()
=
#event handling
def OnRadio(self, event):
iChoice =3D(event.GetInt())
#try activate it
#print iChoice
if iChoice =3D=3D 0:
message =3D 'You have press the A radiobox'
self.myStatusBar.SetStatusText(message,1)
elif iChoice =3D=3D 1:
message =3D 'You have press the B radiobox'
self.myStatusBar.SetStatusText(message,1)
elif iChoice =3D=3D 2:
message =3D 'You have press the C radiobox'
self.myStatusBar.SetStatusText(message,1)
elif iChoice =3D=3D 3:
message =3D 'You have press the D radiobox'
self.myStatusBar.SetStatusText(message,1) =
=
def OnTimer(self, event):
t =3D time.localtime(time.time())
sbTime =3D time.strftime("Astral date %d/%m/%Y are %H:%M:%S", t)
self.myStatusBar.SetStatusText(sbTime,0)
def OnExit(self,event):
self.Destroy()
=
if __name__=3D=3D'__main__':
MyApp =3D wx.PySimpleApp(redirect=3DTrue)
frame=3DMain_Frame()
frame.Show(True)
MyApp.MainLoop() =
More information about the wxpython-users
mailing list