Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要更改 MenuItem 的显示文本。有没有办法在不删除 MenuItem 然后添加另一个具有不同文本的情况下做到这一点?
这在一定程度上取决于您如何创建菜单项,因为 MenuItem 是一个可以包含任何内容的容器。如果您像这样创建它:
menuitem = gtk.MenuItem('This is the label')
然后您可以通过以下方式访问菜单项中的标签小部件:
label = menuitem.child
然后可以将其视为普通标签:
label.set_text('This is the new label')
但是,除非您自己制作菜单项,否则无法保证子小部件会是这样的标签,因此您应该小心。