Display a png, play a sound on button press in wxpython.....

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 6
Reputation: aegis042404 is an unknown quantity at this point 
Solved Threads: 0
aegis042404 aegis042404 is offline Offline
Newbie Poster

Display a png, play a sound on button press in wxpython.....

 
0
  #1
Apr 9th, 2009
Hi, I'm writing a small app in wxpython, on a linux box. I just want to display a graphic and play a short ogg when a gui button is clicked.

Started out as a memory card game, now I just want to display the graphic and play a sound when one of the buttons is pushed. I'm defining the gui buttons as c1, c2, c3 and so on. the graphic and ogg file would be different for each button of course, so I'd like to define them with the rest of the button.

  1. #!/usr/bin/python
  2.  
  3. # gridsizer.py
  4.  
  5. import wx
  6.  
  7. class GridSizer(wx.Frame):
  8. def __init__(self, parent, id, title):
  9. wx.Frame.__init__(self, parent, id, title, size=(750, 590))
  10. card1='/full/path/to/png/A.png'
  11. default='/full/path/to/png/mzzbunns.png'
  12. menubar = wx.MenuBar()
  13. file = wx.Menu()
  14. file.Append(1, '&Quit', 'Exit')
  15. menubar.Append(file, '&File')
  16. self.SetMenuBar(menubar)
  17.  
  18. self.Bind(wx.EVT_MENU, self.OnClose, id=1)
  19.  
  20. sizer = wx.BoxSizer(wx.VERTICAL)
  21.  
  22. c1 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/A.png'))
  23. c2 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/T.png'))
  24. c3 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/H.png'))
  25. c4 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/E.png'))
  26. c5 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/N.png'))
  27. c6 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/S.png'))
  28. c7 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/O.png'))
  29. c8 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/B.png'))
  30. c9 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/C.png'))
  31. c10 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/D.png'))
  32. c11 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/F.png'))
  33. c12 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/G.png'))
  34. gs = wx.GridSizer(3, 4, 15, 15)
  35. gs.Add(c1)
  36. gs.Add(c2)
  37. gs.Add(c3)
  38. gs.Add(c4)
  39. gs.Add(c5)
  40. gs.Add(c6)
  41. gs.Add(c7)
  42. gs.Add(c8)
  43. gs.Add(c9)
  44. gs.Add(c10)
  45. gs.Add(c11)
  46. gs.Add(c12)
  47. sizer.Add(gs, 1, wx.EXPAND)
  48. self.SetSizer(sizer)
  49. self.Centre()
  50. self.Show(True)
  51.  
  52. def OnClose(self, event):
  53. self.Close()
  54.  
  55. app = wx.App()
  56. GridSizer(None, -1, 'Mzz Bunns')
  57. app.MainLoop()

I'd like the graphic to be fairly large, to take up the whole main frame for 5 seconds or so, and die when clicked on, or just die after a few seconds.

Thanks much for any help.....

David
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 921
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Display a png, play a sound on button press in wxpython.....

 
1
  #2
Apr 9th, 2009
Well then i would have a look at wxStaticBitmap, that will handle your images no worries, then you can look at wx.Media.MediaControl for playing your files. Then you just have to bind the buttons in the usual way.

wx.StaticBitmap
http://www.wxpython.org/docs/api/wx....map-class.html

wx.Media.MediaCtrl
http://www.wxpython.org/docs/api/wx....trl-class.html

I wrote tutorials on how to use both of them, find them at: http://wxpython.webs.com/tutorials.htm Take a look at tutorial 5 and 6
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC