我是这个网站的新手,也是Python的新手。我正在开发一个使用wxPython作为GUI的程序。 这个程序正在开发中,将在Windows操作系统的机器上使用。 GUI 使用一些按钮来触发我脚本中的不同进程。我决定尝试使用AGW AquaButtons来提高视觉效果。 我发现一个带焦点的 "AquaButton "在按 "Enter "键时没有反应,而标准的 "wx.Button "却有反应。 下面是工作和不工作代码的例子(大部分是借用类似的问题,感谢 "Rolf of Saxony "和 "Mike Driscoll")。
有没有办法让 "AquaButton"(带焦点)的事件由 "Enter "键触发?
这个能用。
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
frame = wx.Frame.__init__(self, parent, title=title, )
self.panel = wx.Panel(self, -1, size=(200,100))
self.btn1 = wx.Button(self.panel, label='Button 1', id=1)
self.btn1.SetForegroundColour("black")
self.btn2 = wx.Button(self.panel, label='Button 2', id=2)
self.btn2.SetForegroundColour("black")
self.sizer = wx.GridBagSizer(0, 0)
self.sizer.Add(self.btn1, pos=(0, 0), flag=wx.ALIGN_CENTER)
self.sizer.Add(self.btn2, pos=(1, 0), flag=wx.ALIGN_CENTER)
self.text_box = wx.StaticText(self.panel, style = wx.NO_BORDER)
self.text_box.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
self.text_box.SetForegroundColour((40,115,180))
self.sizer.Add(self.text_box, pos=(2,0), flag=wx.ALIGN_CENTER)
self.Bind(wx.EVT_BUTTON, self.button_press)
self.panel.SetSizer(self.sizer)
self.Show()
def button_press(self, event):
Id = event.GetId()
print ('Click Button',str(Id))
retVal = F"Click Button {Id}"
self.text_box.SetLabel(str(retVal))
class AppMenu(wx.App):
def OnInit(self):
'Create the main window and insert the custom frame'
frame = Example(None, 'Example')
frame.Show(True)
return True
app = AppMenu()
app.MainLoop()
这个不行
import wx
import wx.lib.agw.aquabutton as AB
class Example(wx.Frame):
def __init__(self, parent, title):
frame = wx.Frame.__init__(self, parent, title=title, )
self.panel = wx.Panel(self, -1, size=(200,100))
self.btn1 = AB.AquaButton(self.panel, label='Button 1', id=1)
self.btn1.SetForegroundColour("black")
self.btn2 = AB.AquaButton(self.panel, label='Button 2', id=2)
self.btn2.SetForegroundColour("black")
self.sizer = wx.GridBagSizer(0, 0)
self.sizer.Add(self.btn1, pos=(0, 0), flag=wx.ALIGN_CENTER)
self.sizer.Add(self.btn2, pos=(1, 0), flag=wx.ALIGN_CENTER)
self.text_box = wx.StaticText(self.panel, style = wx.NO_BORDER)
self.text_box.SetFont(wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
self.text_box.SetForegroundColour((40,115,180))
self.sizer.Add(self.text_box, pos=(2,0), flag=wx.ALIGN_CENTER)
self.Bind(wx.EVT_BUTTON, self.button_press)
self.panel.SetSizer(self.sizer)
self.Show()
def button_press(self, event):
Id = event.GetId()
print ('Click Button',str(Id))
retVal = F"Click Button {Id}"
self.text_box.SetLabel(str(retVal))
class AppMenu(wx.App):
def OnInit(self):
'Create the main window and insert the custom frame'
frame = Example(None, 'Example')
frame.Show(True)
return True
app = AppMenu()
app.MainLoop()
奇怪的是 AquaButton
使用空格键而不是回车键。导航似乎是通过箭头键或Tab和Shift Tab。如果有疑问,请看源代码。your_python_location/dist-packages/wx/lib/agw/aquabutton.py
我希望这能帮你解决这个问题,如果你的用户不能解决的话 :)