Python 2.7/Windows:ttk 组合框下拉列表显示在最顶层的根窗口下方

发布于 2024-09-29 07:02:49 字数 763 浏览 9 评论 0原文

我正在试验 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱要勇敢去追 2024-10-06 07:02:49

这是 中的已知错误 >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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文