| | |
Does wxPython do the following well?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Okay, so I'm thinking of taking the plunge into wxPython. But it's especially important to me to know if wxPython can do the following things easily and well:
1) Display a vertical array of radio buttons (or perhaps any buttons will do). They must have no labels, and I need to record exactly which button the person pressed. Pressing needs to trigger going to the next screen.
2) Show images/play sounds for a certain duration. For example, I need to show an image for 500 milliseconds, pause for 400 ms, then show another for 500 ms.
Also, I'm looking forward to finding out if certain little annoyances from Tkinter are fixed (e.g., the difficulty in assigning a button command that involves parameters).
Thanks to vegaseat for enticing me with promises of making the cursor invisible...
1) Display a vertical array of radio buttons (or perhaps any buttons will do). They must have no labels, and I need to record exactly which button the person pressed. Pressing needs to trigger going to the next screen.
2) Show images/play sounds for a certain duration. For example, I need to show an image for 500 milliseconds, pause for 400 ms, then show another for 500 ms.
Also, I'm looking forward to finding out if certain little annoyances from Tkinter are fixed (e.g., the difficulty in assigning a button command that involves parameters).
Thanks to vegaseat for enticing me with promises of making the cursor invisible...
The easiest way is to use a wx.RadioBox:
python Syntax (Toggle Plain Text)
import wx class MyFrame(wx.Frame): def __init__(self, parent=None): wx.Frame.__init__(self, parent, wx.ID_ANY, size=(300, 160)) # match to the number of radiobuttons self.mychoices = ['image1', 'image2', 'image3', 'image4'] # create a box with 4 radio buttons, no labels here label_choices = [' ', ' ', ' ', ' '] self.radiobox = wx.RadioBox(self, wx.ID_ANY, " click on a button ", choices=label_choices, style=wx.VERTICAL) # bind mouse click to an action self.radiobox.Bind(wx.EVT_RADIOBOX, self.onAction) # show present selection self.onAction(None) def onAction(self, event): """show the selected choice""" index = self.radiobox.GetSelection() s = "Selected " + self.mychoices[index] # show the result in the frame title self.SetTitle(s) app = wx.App(0) MyFrame().Show() app.MainLoop()
No one died when Clinton lied.
Showing images is easy with wx.StaticBitmap.
http://www.wxpython.org/docs/api/wx....map-class.html
NOTE:This code is borrowed from the sticky
Hope that helps
http://www.wxpython.org/docs/api/wx....map-class.html
NOTE:This code is borrowed from the sticky
python Syntax (Toggle Plain Text)
# show .jpg .png .bmp or .gif image on wx.Panel import wx class ImagePanel(wx.Panel): """ create the panel and put image on it """ def __init__(self, parent, id): # create the panel, this will be self wx.Panel.__init__(self, parent, id) try: # pick your image file you have in the working folder # or use the full file path image_file = 'strawberry.jpg' bmp = wx.Bitmap(image_file) # show the bitmap, image's upper left corner anchors # at panel coordinates (5, 5), default is center wx.StaticBitmap(self, -1, bmp, (5, 5)) # show some image information info = "%s %dx%d" % (image_file, bmp.GetWidth(), bmp.GetHeight()) # the parent is the frame parent.SetTitle(info) except IOError: print "Image file %s not found" % imageFile raise SystemExit # redirect=False sends stdout/stderr to the console window # redirect=True sends stdout/stderr to a wx popup window (default) app = wx.App(redirect=False) # create window/frame, no parent, -1 is the default ID # also increase the size of the frame for larger images frame = wx.Frame(None, -1, size = (480, 320)) # create the panel instance imp = ImagePanel(frame, -1) # show the frame frame.Show(True) # start the GUI event loop app.MainLoop()
Hope that helps
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
Wow, thanks! You guys are great!
Now I just need to know if it can play sounds, and if the images can be displayed for a given duration? Tkinter has the after method for dealing with this. For example:
Also, is there a better way to maximize the frame than just setting its size to the screen size? (When I do that I can still see the frame bar at the top -- in Mac -- and I'd prefer not to, although it's not a big deal.)
Now I just need to know if it can play sounds, and if the images can be displayed for a given duration? Tkinter has the after method for dealing with this. For example:
Python Syntax (Toggle Plain Text)
frame.after(500, doSomethingElse)
Also, is there a better way to maximize the frame than just setting its size to the screen size? (When I do that I can still see the frame bar at the top -- in Mac -- and I'd prefer not to, although it's not a big deal.)
Here is an example without a titlebar and showing fullscreen:
python Syntax (Toggle Plain Text)
# wx.Frame with no title bar and showing fullscreen # modified from vegaseat's example import wx def exit(event): frame.Close(True) app = wx.App(0) # create a window, no-parent, -1 is default ID, style with no titlebar frame = wx.Frame(parent=None, id=-1, pos=(50,100), size=(300,200), style=wx.MINIMIZE_BOX) frame.SetBackgroundColour('green') frame.ShowFullScreen(True, style=wx.FULLSCREEN_ALL) # provide exit for a frame without titlebar quit = wx.Button(frame, id=-1, label='Exit', pos=(0, 0)) quit.Bind(wx.EVT_BUTTON, exit) # show the window frame.Show(True) # start the event loop app.MainLoop()
drink her pretty
wxPython has its own wait/delay functions:
wx.Sleep(seconds)
wx.MilliSleep(milliseconds)
The best way is to use wx.FutureCall(), for an example see:
http://www.daniweb.com/forums/showpo...&postcount=108
wx.Sleep(seconds)
wx.MilliSleep(milliseconds)
The best way is to use wx.FutureCall(), for an example see:
http://www.daniweb.com/forums/showpo...&postcount=108
Last edited by vegaseat; May 20th, 2009 at 2:32 pm.
May 'the Google' be with you!
Oh yeah, wxPython has its own sound functions, one of them is wx.Sound() ...
Also check the example at:
http://www.daniweb.com/forums/post872330-109.html
python Syntax (Toggle Plain Text)
# playing a wave file with wxPython's # wx.Sound(fileName, isResource=False) # and its method Play(flags=wx.SOUND_ASYNC) # vega import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) self.SetBackgroundColour("red") # pick a .wav sound file you have ... sound = wx.Sound('anykey.wav') # wx.SOUND_SYNC --> sound plays completely through # wx.SOUND_ASYNC --> sound can be stopped or reset # wx.SOUND_ASYNC|wx.SOUND_LOOP --> loop until stopped # with sound.Stop() sound.Play(wx.SOUND_SYNC) app = wx.App(0) # create a MyFrame instance and show the frame MyFrame(None, 'wx.Sound()', (300, 100)).Show() app.MainLoop()
http://www.daniweb.com/forums/post872330-109.html
Last edited by vegaseat; May 20th, 2009 at 3:06 pm.
May 'the Google' be with you!
I have to say, I am really impressed. Somehow when I was first looking at wxPython ages ago, I must have downloaded the worst tutorial ever, because it seemed so obtuse and useless for my needs -- yet now it seems so simple and has everything I need built in.
I'm going to make a go at switching over my program today... wish me luck! Thanks for all the help!
I'm going to make a go at switching over my program today... wish me luck! Thanks for all the help!
![]() |
Similar Threads
- Instal of wxPython (Python)
- no WxPython here? (Python)
Other Threads in the Python Forum
- Previous Thread: access login module from server to client....
- Next Thread: Help with text-based game in Python
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti apache approximation array backend basic beginner book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary dynamic examples excel file filename float format ftp function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive redirect refresh scrolledtext software ssh stamp statictext statistics string strings table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame wxpython






