Hi, so I'm currently porting one of my applications (it's a media player) from Tkinter to wxPython and I am having some trouble as this is the first wx application I have attempted. I am trying to create something similar to this. However, I can't figure out the wxPython code for it. I got to the point of creating three listboxes and putting them in a sizer and that worked well; but, once I add static text above them, everything poops out. Here's a picture of what my bug looks like. Here's some code, too:
#!/usr/bin/python
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))
songs1 = ["Take It Easy", "Before I Forget", "Welcome", "Blitzkreig", "One"]
songs2 = ["The Fray", "Metallica", "AC/DC", "The Eagles", "Godsmack"]
songs3 = ["Hell Freezes Over", "Believe", "Indestructible", "All Hope is Gone", "Ten Thousand Fists"]
attrpanel = wx.Panel(self, -1)
self.songAttr = wx.StaticText(attrpanel, -1, "Songs", (170, 25), style=wx.ALIGN_CENTRE)
self.artistAttr = wx.StaticText(attrpanel, -1, "Artists", (170, 25), style=wx.ALIGN_CENTRE)
self.albumAttr = wx.StaticText(attrpanel, -1, "Albums", (170, 25), style=wx.ALIGN_CENTRE)
attrSizer = wx.BoxSizer(wx.HORIZONTAL)
attrSizer.Add(self.songAttr, 1)
attrSizer.Add(self.artistAttr, 1)
attrSizer.Add(self.albumAttr, 1)
attrpanel.SetSizer(attrSizer)
self.Centre()
lbpanel = wx.Panel(self, -1)
self.songBox = wx.ListBox(lbpanel, 1, wx.DefaultPosition, (170, 130), songs1, wx.LB_SINGLE)
self.artistBox = wx.ListBox(lbpanel, 2, wx.DefaultPosition, (170, 130), songs2, wx.LB_SINGLE) #wx.DefaultPosition
self.albumBox = wx.ListBox(lbpanel, 3, wx.DefaultPosition, (170, 130), songs3, wx.LB_SINGLE)
lbSizer = wx.BoxSizer(wx.HORIZONTAL)
lbSizer.Add(self.songBox, 1)
lbSizer.Add(self.artistBox, 1)
lbSizer.Add(self.albumBox, 1)
lbpanel.SetSizer(lbSizer)
self.Centre()
self.songBox.SetSelection(0)
self.artistBox.SetSelection(0)
self.albumBox.SetSelection(0)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
self.Bind(wx.EVT_LISTBOX, self.SongSelect, id=1)
self.Bind(wx.EVT_LISTBOX, self.ArtistSelect, id=2)
self.Bind(wx.EVT_LISTBOX, self.AlbumSelect, id=3)
def OnClose(self, event):
self.Close()
def SongSelect(self, event):
index = event.GetSelection()
self.artistBox.SetSelection(index)
self.albumBox.SetSelection(index)
def ArtistSelect(self, event):
index = event.GetSelection()
self.songBox.SetSelection(index)
self.albumBox.SetSelection(index)
def AlbumSelect(self, event):
index = event.GetSelection()
self.songBox.SetSelection(index)
self.artistBox.SetSelection(index)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'wxCAKE')
frame.Centre()
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()
What the heck am I doing wrong here?
Thanks in advance.