我有一个简单的 Python + Tkinter 应用程序,它显示 10 个项目的列表:
import Tkinter, ttk
list = ttk.Treeview( Tkinter.Tk() )
list.pack( fill = Tkinter.BOTH, expand = 1 )
items = [ list.insert( '', 'end', text = str( i ) ) for i in range( 10 ) ]
list.selection_set( items[ 0 ] )
list.focus_set() # This is not working - list has no focus :(
Tkinter.mainloop()
是否可以修改它,以便在应用程序启动后,列表将具有焦点,我可以通过向上和向下箭头移动选择?应用程序启动后,应用程序的窗口具有焦点,但我无法使用箭头移动选择,直到我用鼠标单击列表:(。我尝试了 and 的不同组合focus_set()
,focus_force()
但它不起作用。
在 Windows 7、OSX 10.7 和 Ubuntu 12.04 上使用 Python 2.7 检查
更新
如果“Treeview”更改为其他一些小部件,例如“Button”,则焦点正在工作。所以似乎我以某种方式错误地为 Treeview 设置了焦点。