<p>是的,它可以禁用菜单,但仍然能够打开它只是为了查看列表。在<code>OptionMenu</code>中使用的菜单是tkinter <code>Menu()</code>,您可以访问它。你知道吗</p>
<p><strong>示例:</strong></p>
<pre><code>Op = OptionMenu(root, var, 'First', 'Second', 'Third')
Op.pack()
# Op_Menu is the Menu() class used for OptionMenu
Op_Menu = Op['menu']
</code></pre>
<p>然后您可以使用<code>Op</code>菜单执行与<code>Menu()</code>相同的操作</p>
<hr/>
<h2>在你的情况下,如何禁用?你知道吗</h2>
<p>我们可以根据用户使用<code>menu.entryconfig(index, options)</code>来配置<code>state = 'disabled' / 'normal'</code>。你知道吗</p>
<p><strong>示例:</strong></p>
<pre><code>import tkinter as tk
root = tk.Tk()
root.geometry('250x250+100+100')
str = tk.StringVar()
str.set('Select')
Op = tk.OptionMenu(root, str, "First", "Second", "Third")
Op.pack()
# This will disable the First and Third entries in the Op
# state = 'disable' / 'normal'
Op['menu'].entryconfig(0, state='disable')
Op['menu'].entryconfig("Third", state='disable')
entries = Op['menu'].index('end') # This will get the total no. of entries.
# If you want to disable all of the entries uncomment below 2 lines.
# for i in range(entries+1):
# Op['menu'].entryconfig(i, state='disable')
root.mainloop()
</code></pre>
<p><img src="https://i.stack.imgur.com/0Dxmj.png" alt="https://i.stack.imgur.com/0Dxmj.png" title="CENTERED!"/></p>
<p>为了更好地理解<code>Menu()</code>是如何在<code>OptionMenu</code>类中定义的,可以<a href="https://github.com/python/cpython/blob/ad4ed872415d00fcdfaa52a08108ec752b115000/Lib/tkinter/__init__.py#L3946" rel="nofollow noreferrer">check the source code of ^{<cd9>} class</a>。<em>(从第<a href="https://github.com/python/cpython/blob/ad4ed872415d00fcdfaa52a08108ec752b115000/Lib/tkinter/__init__.py#L3959" rel="nofollow noreferrer">3959</a>行开始)</em></p>