| | |
wxpython button help
Thread Solved |
•
•
Join Date: May 2009
Posts: 2
Reputation:
Solved Threads: 0
Hi
I'm trying to create a dialog box with GenBitmapTextButton buttons. When I create the dialog using the standard button, I can use the enter key to push the button, and the escape key to cancel the dialog.
However, when I use the GenBitmapTextButton, neither the enter nor the escape key work. The enter key behaves in the same way as the tab key. I've included a skeleton example below that illustrates the issue (to run the code you merely need to include two images called ok.png and cancel.png in the same directory as the file containg the code).
Do I need to bind some event to the button/dialog to make this work in the same manner as the simple case?
I'm using python version 2.5 and wxpython version 2.8.9.2 on windows
Any help would be greatly appreciated.
I'm trying to create a dialog box with GenBitmapTextButton buttons. When I create the dialog using the standard button, I can use the enter key to push the button, and the escape key to cancel the dialog.
However, when I use the GenBitmapTextButton, neither the enter nor the escape key work. The enter key behaves in the same way as the tab key. I've included a skeleton example below that illustrates the issue (to run the code you merely need to include two images called ok.png and cancel.png in the same directory as the file containg the code).
Do I need to bind some event to the button/dialog to make this work in the same manner as the simple case?
I'm using python version 2.5 and wxpython version 2.8.9.2 on windows
Any help would be greatly appreciated.
python Syntax (Toggle Plain Text)
import wx import wx.lib.buttons class SimpleDialog(wx.Dialog): def __init__(self, text): wx.Dialog.__init__(self, parent=None, id=wx.ID_ANY, title="SimpleDialog", pos=wx.DefaultPosition, size=(250,150)) wx.StaticText(self, -1, text, wx.Point(15, 20)) okButton = wx.Button(self, wx.ID_OK, ' OK ', wx.Point(35, 90), wx.DefaultSize) okButton.SetDefault() cancelButton = wx.Button(self, wx.ID_CANCEL, ' Cancel ', wx.Point(135, 90), wx.DefaultSize) class BitmapDialog(wx.Dialog): def __init__(self, text): wx.Dialog.__init__(self, parent=None, id=wx.ID_ANY, title="BitmapDialog", pos=wx.DefaultPosition, size=(250,150)) wx.StaticText(self, -1, text, wx.Point(15, 20)) okButton = wx.lib.buttons.GenBitmapTextButton(self, wx.ID_OK, wx.Bitmap('ok.png'), ' OK ', (15, 80), (100, -1)) okButton.SetBezelWidth(3) okButton.SetDefault() cancelButton = wx.lib.buttons.GenBitmapTextButton(self, wx.ID_CANCEL, wx.Bitmap('cancel.png'), ' Cancel ', (130, 80), (100, -1)) cancelButton.SetBezelWidth(3) if __name__ == '__main__': app = wx.PySimpleApp() dlg1 = SimpleDialog("SimpleDialog Text") if dlg1.ShowModal() == wx.ID_OK: print "SimpleDialog OK" else: print "SimpleDialog Cancel" dlg1.Destroy() dlg2 = BitmapDialog("BitmapDialog Text") if dlg2.ShowModal() == wx.ID_OK: print "BitmapDialog OK" else: print "BitmapDialog Cancel" dlg2.Destroy() app.MainLoop()
In order to make buttons behave like standard buttons in your dialog box, you simply create an image button from a standard button and an image:
Actually, the way these buttons respond to keystrokes depends on the OS.
python Syntax (Toggle Plain Text)
class BitmapDialog(wx.Dialog): def __init__(self, text): wx.Dialog.__init__(self, None, -1, title="BitmapDialog", size=(250,150)) bmp = wx.Bitmap('ok.png') w, h = bmp.GetSize() x = 35 y = 90 wx.StaticBitmap(self, -1, bmp, pos=(x, y)) okButton = wx.Button(self, wx.ID_OK, ' OK ', pos=(x+w, y), size=(w*2, h)) okButton.SetDefault() bmp = wx.Bitmap('cancel.png') w, h = bmp.GetSize() x = 135 y = 90 wx.StaticBitmap(self, -1, bmp, pos=(x, y)) cancelButton = wx.Button(self, wx.ID_CANCEL, ' Cancel ', pos=(x+w, y), size=(w*2, h))
drink her pretty
•
•
Join Date: May 2009
Posts: 2
Reputation:
Solved Threads: 0
Thanks Ene.
This does seem to be the only solution.
I'll play around with the layout until it looks right. The GenBitmapTextButton doesn't have the same class hierarchy as the BitmapButton, and as a result it doesn't support the features of the standard button.
Another thing I noticed was how the GenButton doesn't support shortcut keys. "&OK" on the standard button is displayed as OK, but in the GenButton it is &OK.
What you gain in prettiness in the GenButton you lose in functionality
Thanks again
This does seem to be the only solution.
I'll play around with the layout until it looks right. The GenBitmapTextButton doesn't have the same class hierarchy as the BitmapButton, and as a result it doesn't support the features of the standard button.
Another thing I noticed was how the GenButton doesn't support shortcut keys. "&OK" on the standard button is displayed as OK, but in the GenButton it is &OK.
What you gain in prettiness in the GenButton you lose in functionality
Thanks again
![]() |
Similar Threads
- Python GUI Programming (Python)
- Starting wxPython (GUI code) (Python)
- Display a png, play a sound on button press in wxpython..... (Python)
- wx.CallAfter() (Python)
- How to create Help in wxPython? (Python)
- wxPython Event Handler (Python)
- wxpython Setfocus problem (Python)
- Instal of wxPython (Python)
Other Threads in the Python Forum
- Previous Thread: Formatting Data
- Next Thread: Python Spider Help
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






