473,414 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

WxButton

I have a simple application in a Frame, in it I have a button that I want to
press when I hit enter. How can I do this? I know with textctrl's you have
the EVT_TEXT_ENTER event to do things for you when enter is pressed, can I do
the same with a button. I know in WxWidgets for C++ you can put it in a
WxDialog and it will do all that anyway, but my version of WxPython doesn't
have that
Jul 18 '05 #1
6 2958
ok this is slightly confusing , so I am just gonna throw out some ides.
You could define an accelerator table and just bind wxACCEL_NORMAL,
and WXK_RETURN to an id number.
then set an event handler to operate your button(more on that later).
Or you can set an event to just look for a certain key :
Declare this event.

py> EVT_KEY_DOWN(self, self.OnKeyPressed)

And do something like this.

py> def OnKeyPressed(self, event):
.... key = event.KeyCode()
.... if key == WXK_RETURN:
.... BtnPressCode()

Ok now the button thing what are you wanting just to activate the
button or to toggle the button or.?
There are many buttons types and they have very different methods!
I will leave that code up to you ( just do a google search for wxButton
or wxToggleButton or even wxBitmapButton and many more just search the
docs they are very helpful, and always this is covered somewhere in the
wx demo ;)
Hth,
M.E.Farmer

Jul 18 '05 #2
That's kindof where I want to go, how can I detect whether or not my button has
focus. Basically I only want to press it with enter if it has focus.
Jul 18 '05 #3
Have you explored the wxPython Demo application? It is a pretty helpful
learning tool.

Jul 18 '05 #4
Yes I have actually, I still can't figure out how to have my application detect
if a control has focus. If I could, I could just use the keydown event with an
if statement to push my button when it has focus and enter is pressed.
Jul 18 '05 #5
Disregard all my posts on this thread, I just downloaded Boa-constructor which
has WxDialogs making my life so much simpler. Thanks for all the help though.
I was using SPE which uses WxGlade to make gui's, which isn't so bad if you're
familiar with the way Java works on GUIs that is, but Boa-Constructor is really
cool!
Jul 18 '05 #6
LutherRevisited wrote:
Yes I have actually, I still can't figure out how to have my application detect if a control has focus. If I could, I could just use the keydown event with an if statement to push my button when it has focus and enter is

pressed.

I am gonna try and explain how to fish ;)
Lets start with what we want to know :
What methods does wx.Button have, how do I find out?
0) Do a search for wx.Button on Google.
1) Consult the very extensive documentation available from
wxPython.org
if it didn't come with your distro.
2) Consult the Demo that comes with wxPython ( I see you have
tried )
3) Open an interpreter and try print dir(mybutton)
and see what it gives you......very informative!
Actually find out what it your object really supports,
even better than out of date docs.
4) Search a newsgroup for wx.Button or wxButton
5) Ask a newsgroup

Now on to some hints into the workings of wx.
Just about everything in wx inherits from something ( usually window ).
That means you have to look at all the bases to see what all is
available in an object. wx.Button has window as a parent, that means we
can simply use window's methods ,like SetFocus().
Always look at the bases to figure out what you have available you can
be surprised what an object is capable of.
I still dont know what you are trying to achieve.
Are you using regular buttons or toggles or bitmaps or who knows, it
matters.
I am going to mention this if you just want to activate the button that
has focus using the return key than it already works like that just tab
to the button and press return.
If you want to make a button focused by default you can use
SetDefault()
Sounds like you are trying to hard to do something simple, try less.
Hth,
M.E.Farmer

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pilu | last post by:
hi,given that I'm a newbie in python, I have a little problem with wx... Maybe it's a stupid thing,but if u want help me! I used wxglade to generate a simple window with a button! wxglade...
0
by: fowlertrainer | last post by:
Hello ! I want to create a tool for mp3 files in wx. Some sections of the code (see below) is copied from wx demo. Problems: 1.) the wxStaticText is not centered vertically 2.) the...
19
by: Grant Edwards | last post by:
I've decided to learn wxPython, and I'm afraid I just don't grok the whole "id" thing where you have to pull unique integers out of your, er, the air and then use those to refer to objects: ...
0
by: Piet | last post by:
Hello wxPythoneers. I have a problem with a dialog box derived from wxFrame which has a wxComboBox as main element. Depending on the entry selected from the ComboBox, the dialog box will be...
1
by: flupke | last post by:
Hi, i'm trying to convert my java console app to a python gui. Now, the only problem i seem to have at the moment are the resizers for the layout. It seems that for the purpose of what i'm...
108
by: Zooko O'Whielacronx | last post by:
I'm a fan of Greg Ewing's PyGUI . I used it to code a simple game for my son , and enjoyed it. Programming with wxPython feels like programming with a C++ tool that has been wrapped in Python....
0
by: mee-shell | last post by:
Hi, I am a python newbie. I have created a tool for capturing the screen shot. I want to be able to do the screen capture with the keydown event as well. The tool worked fine when it first...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
1
by: grays | last post by:
I Create A Button Named ABtn and Blind OnABtnClick() with it . How can i Call the ABtn Click Event just like use Abtn.click in Delphi?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.