如何在创建菜单时删除 tkinter - - - - 行 [英] How to remove tkinter - - - - line's when creating menu

查看:33
本文介绍了如何在创建菜单时删除 tkinter - - - - 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is this line and How to remove the lines that appear automatically when creating a menu:

推荐答案

使用 tearoff=0.来自 NM 技术 Tkinter 参考:

撕掉

通常情况下,一个菜单可以被撕掉:选择列表中的第一个位置(位置 0)被撕掉元素占据,额外的选择从位置 1 开始添加.如果你设置了 撕下=0,菜单将没有撕下功能,并且从位置0开始添加选项.

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.

您可以在此示例中看到不同之处:

You can see the difference in this example:

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()

这篇关于如何在创建菜单时删除 tkinter - - - - 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆