我正在看这篇文章:https ://stackoverflow.com/a/2262200 ,我在编写的小东西中有一个非常相似的设置。我的问题是,一旦 entrycompletion 完成,并且输入框有 url,我如何从完成中获取该 url 到变量中?entry.get_text() 似乎不起作用,我尝试的其他一切似乎都给了我一个对象或地址。如果您不想点击,这里是来自上述链接的报价。
# simplified example from the tutorial
import gtk
urls = [
'http://www.google.com',
'http://www.google.com/android',
'http://www.greatstuff.com',
'http://www.facebook.com',
]
liststore = gtk.ListStore(str)
for s in urls:
liststore.append([s])
completion = gtk.EntryCompletion()
completion.set_model(liststore)
completion.set_text_column(0)
entry = gtk.Entry()
entry.set_completion(completion)
# boilerplate
window = gtk.Window()
window.add(entry)
window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()
gtk.main()