我正在使用 wxPython (Phoenix)。 我根据这些 guidelines 编写了一个带有自定义自动完成器的小应用程序,但失败并出现以下错误:
Traceback (most recent call last):
File "try2.py", line 33, in <module>
frame = TextFrame()
File "try2.py", line 26, in __init__
basicText.AutoComplete(MyTextCompleter)
TypeError: TextEntry.AutoComplete(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'sip.wrappertype'
overload 2: argument 1 has unexpected type 'sip.wrappertype'
这是代码:
import wx
class MyTextCompleter(wx.TextCompleterSimple):
def __init__(self):
wx.TextCompleterSimple.__init__(self)
def GetCompletions(self, prefix, res):
if prefix == "a":
res.append("This order is")
res.append("very important")
elif firstWord == "b":
res.append("z - It's not in")
res.append("a - lexicographic order")
else:
res.append("bye")
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example', size=(300, 100))
panel = wx.Panel(self, -1)
basicLabel = wx.StaticText(panel, -1, "Basic Control:")
basicText = wx.TextCtrl(panel, -1, "I've entered some text!", size=(175, -1))
basicText.SetInsertionPoint(0)
basicText.AutoComplete(MyTextCompleter)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([basicLabel, basicText])
panel.SetSizer(sizer)
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()
注释掉 basicText.AutoComplete(MyTextCompleter)
时,它成功运行(没有自动完成)
最佳答案
我应该更彻底地警告你:wxPython Phoenix 是 wxPython 的 future (因为,与经典版本相比,它也支持 Python 3)。也就是说,这并不意味着一切都美好而 Shiny 。我个人的建议是继续使用经典(或者换句话说:现在在经典中有效的方法很可能也适用于凤凰城)。在凤凰城,你会更频繁地遇到这样的错误。
幸运的是,在这种特殊情况下,已经做了其他事情:
<wx.TextCtrl>.AutoComplete(…)
确实接受字符串列表。这已经在 2.9.0/classic 中运行。请参阅documentation for wx.TextEntry
/AutoComplete .
关于python - WxPython - 编写自动完成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31243376/