在一个简单的图形用户界面中,当用户填写了必要的文本字段时,我在按钮上使用SetDefault()
,因此很明显,如果用户现在按下return键,按钮就会被按下。wxPython中的SetDefault()
不带参数,所以无法调用SetDefault(False)
,也找不到合适的接口调用来反转默认状态。
如何在wxPython中反转或撤消SetDefault()
调用的操作?
发布于 2018-07-31 07:20:13
正如我现在了解到的,解决方案是在按钮上使用Enable()
和Disable()
。我试图通过“撤销”SetDefault()
实现的实际上就是Disable()
所做的事情。以下是现在工作代码的节略版本:
...
self.login.Bind(wx.EVT_TEXT, self.on_text)
self.password.Bind(wx.EVT_TEXT, self.on_text)
....
self.cancel_button = wx.Button(panel, wx.ID_ANY, "Cancel")
self.cancel_button.Bind(wx.EVT_KEY_DOWN, self.on_escape)
self.ok_button = wx.Button(panel, wx.ID_ANY, "OK")
self.ok_button.Bind(wx.EVT_KEY_DOWN, self.on_ok_enter_key)
self.ok_button.SetDefault()
self.ok_button.Disable()
....
def on_text(self, event):
if self.login.GetValue() and self.password.GetValue():
self.ok_button.Enable()
else:
self.ok_button.Disable()
https://stackoverflow.com/questions/51560391
复制相似问题