Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to SetDefault()?
    primarykey
    data
    text
    <p>I'm new to wxpython but I have to edit a (large) given code:</p> <pre><code>bsButtons = wx.BoxSizer(wx.HORIZONTAL) self.cmdOk = wx.Button(self, label=_(u"Ok")) self.cmdOk.Bind(wx.EVT_BUTTON, self.OnOk) bsButtons.Add(self.cmdOk, border=4, flag=wx.RIGHT) self.cmdCancel = wx.Button(self, label=_(u"Abbrechen")) self.cmdCancel.Bind(wx.EVT_BUTTON, self.OnCancel) bsButtons.Add(self.cmdCancel) </code></pre> <p>...</p> <pre><code>def OnOk(self, event): self.EndModal(wx.ID_OK) def OnCancel(self, event): self.EndModal(wx.ID_CANCEL) </code></pre> <p>I want to set the focus on the "OK" Button by default, so that the "Enter"-Key will execute this button. I already tried to add this line:</p> <pre><code>self.cmdOk.SetDefault() </code></pre> <p>But this didn't work. (no error, but pressing Enter didn't had an effect) Anyone who can help me? Thanks!</p> <p>Edit: I inserted the following:</p> <pre><code>self.Bind(wx.EVT_KEY_DOWN, self.on_key_down) ... def on_key_down(self, event): if event.GetKeyCode() == wx.WXK_RETURN: self.EndModal(wx.ID_OK) else: event.Skip() </code></pre> <p>But this does not work. There is missing something: I know the first line has to look like this:</p> <pre><code>self.button.Bind(wx.EVT_BUTTON, self.OnButton) </code></pre> <p>But I don't know what "button" is in my case?!</p> <p>Edit2: Finally it works:</p> <pre><code>self.etcFormula.Bind(wx.EVT_KEY_DOWN, self.on_key_down) </code></pre> <p>etcFormula is the edit line I was talking about (where the focus is). So now I understood that I have to refer to this edit line when I want to catch the Enter-button.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload