Problem with wxPython form

aapost aapost at idontexist.club
Sun Mar 12 15:48:32 EDT 2023


On 3/10/23 15:15, Chris wrote:
> Hi everyone. I'm new to Python and wxPython. I've got a form I use to 
> calculate the Sq In of a leather project.
> 
> I'm using python 3.9.13 and wxPython 4.20
> 
> I'm having the following issues:
> 1) When I come into the form, no grid cell has the focus set - I start 
> typing and nothing happens. I have to click the cell.
> If I hit Tab or Enter, the OnKeyDown fires, but does not move to the 
> appropriate cell - it does nothing but run the update and move off of 
> the current cell.
> The action I'm trying to make is this
> ENTER KEY: Always go down 1 row and to col 0
> TAB, if Col 0 Move to Col 1 on same row, if Col 1 go to Row +1, Col 0
> I also need to have what3ever cell it is supposed to land on to get the 
> focus so I can just type.
> Currently I have to click in each cell I want/need to add.
> There could be up to 20 pieces of leather with differing sizes, so in 
> order to accurately calculate the Sq In, I need to get all the 
> measurements in.
> The form, one of several tabs, comes up and does everything else I've 
> coded for great. Just no navigation.
> Can anyone assist? Here is the module with the form

Your source was badly mangled by whatever you submitted it in, so it was 
very difficult to parse. Additionally, it is usually best to strip your 
code down to a minimal example of the issue, and remove any references 
to modules that are likely not publicly available (i.e. alwlogic) 
(putting basic dummy data in place if need be).

That being said:
2 things will likely address your issue, remove 
self.grid.SetCellHighlightPenWidth(0) since this is making the highlight 
box of the selected cell invisible, this is preventing you from seeing 
that your tabs and enters are working as you are expecting.

Next, the wx.EVT_KEY_DOWN binding is grabbing all key presses, and your 
function is only addressing 2 keys, you need to add an else: to the end 
with an event.Skip() to allow the default behaviors of the grid cells to 
pass through for other keys (i.e. typing).

That should get you the behavior you need.




More information about the Python-list mailing list