0 Replies - 4893 Views - Last Post: 09 February 2012 - 04:42 AM Rate Topic: -----

#1 raspinudo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 61
  • View blog
  • Posts: 232
  • Joined: 19-September 11

Quick Audio Question

Posted 09 February 2012 - 04:42 AM

Hey All,

I am just starting to learn python, and I must say I am really enjoying it. I have however run into my first snag. I am trying to get an audio file to play when I click a bitmap button, yet when I click it I am getting a segmentation fault. If someone could see the error in my code I would be very appreciated.

import wx

class gui(wx.Frame):

	def __init__(self,parent,id):
		wx.Frame.__init__(self,parent,id,'Window Test', size=(630,470))
		panel=wx.Panel(self)
		button=wx.Button(panel,label="exit",pos=(300,300), size=(40,30))		
		self.Bind(wx.EVT_BUTTON, self.closebutton, button)			
		self.Bind(wx.EVT_CLOSE, self.closewindow)
		
		status=self.CreateStatusBar()		
		menubar=wx.MenuBar()
		first=wx.Menu()
		second=wx.Menu()
		first.Append(wx.NewId(), "new window", "new window opening..")
		menubar.Append(first, "file")
		self.SetMenuBar(menubar)		

	        pic = wx.Image("yeah.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
		self.button=wx.BitmapButton(panel,-1, pic, pos=(0,0))
		self.Bind(wx.EVT_BUTTON, self.hit, self.button)
		self.button.SetDefault()

	def hit(self, evt):
        	self.sound = wx.Sound('RingToneSong.wav')
        	if self.sound.IsOk():
            		self.sound.Play(wx.SOUND_ASYNC)
        	else:
            		wx.MessageBox("Invalid sound file", "Error")

   	def closebutton(self,event):
		self.Close(True)
		box = wx.MessageDialog(None, 'Are you sure?', 'Close Message', wx.YES_NO)
                ans = box.ShowModal()
                box.Destroy()

	def closewindow(self,event):
		self.Destroy()

if __name__=='__main__':
	app=wx.PySimpleApp()
	frame=gui(parent=None,id=-1)
	frame.Show()
	app.MainLoop()



Thanks and Happy Coding :bananaman:

Edit, dont mind some of the random tidbits; I have been using this as my sandbox for testing all of the different gui features in wxPython

This post has been edited by raspinudo: 09 February 2012 - 04:43 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1