| | |
Display a png, play a sound on button press in wxpython.....
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 6
Reputation:
Solved Threads: 0
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.
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
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.
Python Syntax (Toggle Plain Text)
#!/usr/bin/python # gridsizer.py import wx class GridSizer(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(750, 590)) card1='/full/path/to/png/A.png' default='/full/path/to/png/mzzbunns.png' menubar = wx.MenuBar() file = wx.Menu() file.Append(1, '&Quit', 'Exit') menubar.Append(file, '&File') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnClose, id=1) sizer = wx.BoxSizer(wx.VERTICAL) c1 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/A.png')) c2 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/T.png')) c3 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/H.png')) c4 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/E.png')) c5 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/N.png')) c6 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/S.png')) c7 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/O.png')) c8 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/B.png')) c9 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/C.png')) c10 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/D.png')) c11 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/F.png')) c12 = wx.BitmapButton(self, -1, wx.Bitmap('/full/path/to/png/G.png')) gs = wx.GridSizer(3, 4, 15, 15) gs.Add(c1) gs.Add(c2) gs.Add(c3) gs.Add(c4) gs.Add(c5) gs.Add(c6) gs.Add(c7) gs.Add(c8) gs.Add(c9) gs.Add(c10) gs.Add(c11) gs.Add(c12) sizer.Add(gs, 1, wx.EXPAND) self.SetSizer(sizer) self.Centre() self.Show(True) def OnClose(self, event): self.Close() app = wx.App() GridSizer(None, -1, 'Mzz Bunns') 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
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
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
Check out my Site | and join us on IRC | Python Specific IRC
![]() |
Other Threads in the Python Forum
- Previous Thread: web python control transfer from one page to another
- Next Thread: Constructing a simple GUI with Tkinter
| Thread Tools | Search this Thread |
accessdenied advanced application argv beginner change color command convert csv cursor def dictionary digital dynamic dynamically edit editing enter event examples excel file float format frange function google gui homework i/o import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame newb number numbers numeric obexftp output parameters parsing path port prime programming projects py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session simple skinning smtp sprite stderr string strings subprocess syntax table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape windows wxpython





