Python 2.7/Windows:ttk 组合框下拉列表显示在最顶层的根窗口下方
我正在试验 Python 2.7 附带的新 ttk Tile 增强功能。
Windows 7:下面的代码演示了当根窗口配置为最上面的窗口(“始终在顶部”)时,组合框下拉列表如何显示在根窗口后面。如果注释掉行 """ root.attributes( '-topmost', 1 )""" ,则组合框下拉列表将出现在根窗口中(如预期)。
任何人都可以解决此行为,以便我们可以将组合框与“最顶层”窗口一起使用?
# sample code that illustrates problem described above
import Tkinter as tkinter
import ttk
root = tkinter.Tk()
panelCombo = ttk.Frame( root )
panelCombo.pack( side='top', fill='x', padx=12, pady=8 )
valCombo = ( 'cat', 'dog', 'pig' )
varCombo = tkinter.StringVar()
varCombo.set( 'fish' )
cboCombo = ttk.Combobox( panelCombo, values=valCombo, textvariable=varCombo )
cboCombo.pack( side='left', anchor='w', padx=12, pady=8 )
# make our window 'alwaysontop'
root.attributes( '-topmost', 1 )
root.mainloop()
I'm experimenting with the new ttk Tile enhancements that ship with Python 2.7.
Windows 7: The code below demonstrates how the combobox dropdown shows up BEHIND our root window when the root window is configured as a topmost window ("always on top"). If you comment out the line """ root.attributes( '-topmost', 1 )""" then the combobox dropdown appears within the root window (as expected).
Anyone have any workarounds for this behavior so we can use comboboxes with 'topmost' windows?
# sample code that illustrates problem described above
import Tkinter as tkinter
import ttk
root = tkinter.Tk()
panelCombo = ttk.Frame( root )
panelCombo.pack( side='top', fill='x', padx=12, pady=8 )
valCombo = ( 'cat', 'dog', 'pig' )
varCombo = tkinter.StringVar()
varCombo.set( 'fish' )
cboCombo = ttk.Combobox( panelCombo, values=valCombo, textvariable=varCombo )
cboCombo.pack( side='left', anchor='w', padx=12, pady=8 )
# make our window 'alwaysontop'
root.attributes( '-topmost', 1 )
root.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是
中的已知错误 >Tk
工具包。它已在版本 8.5.6 中修复。也许您只需要等待该版本进入 Python 即可。That's a known bug in the
Tk
toolkit. It was fixed in release 8.5.6. Maybe you just need to wait until that release makes its way into Python.