python - 创建菜单时如何删除 tkinter - - - - 行

标签 python tkinter

这行是什么以及如何删除创建菜单时自动出现的行:

Image of the output

最佳答案

使用tearoff=0。来自NM Tech Tkinter reference :

tearoff

Normally, a menu can be torn off: the first position (position 0) in the list of choices is occupied by the tear-off element, and the additional choices are added starting at position 1. If you set tearoff=0, the menu will not have a tear-off feature, and choices will be added starting at position 0.

您可以在此示例中看到差异:

from tkinter import *

root = Tk()

menubar = Menu(root)

tearoff = Menu(menubar, tearoff=1)
tearoff.add_command(label="Tearoff")
menubar.add_cascade(label="Tearoff", menu=tearoff)

notearoff = Menu(menubar, tearoff=0)
notearoff.add_command(label="No Tearoff")
menubar.add_cascade(label="No Tearoff", menu=notearoff)

root.config(menu=menubar)
root.mainloop()

关于python - 创建菜单时如何删除 tkinter - - - - 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55088055/

相关文章:

python - 如何让 Tkinter 文件对话框只显示文本文件?

python - 无法在 Mac 上安装 pip2.7

python - 无法使 tkinter 的 StringVar 跟踪方法起作用

linux - 无法打开 Pyinstaller 的输出文件

Python tkinter : Add button to menu bar

python - 使用 TKInter 下拉菜单中的选项分配变量 - Python 2.7

python - 从 Python 字符串中剥离字符

python-3.x - Python3.6向cv2处理的视频添加音频

python - 最早常用的Python版本

python - 无法在我的 Raspberry Pi 上使用 pip 安装 Flask