通过使用子菜单栏,我将文本大小作为输入,并根据该输入更改 text_area 中的字体大小。但问题在于巨大的子菜单栏。有没有办法调整它的高度?
为了更清楚地了解问题,请参阅下图,
from tkinter import *
root = Tk()
root.title("Notepad")
root.geometry("900x570+270+30")
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text_area = Text(root, bg="azure2", fg="Black", yscrollcommand = scrollbar.set)
text_area.pack(expand=True, fill="both")
# Creating top level menubar
menubar = Menu(root)
def font_size(size):
# I'm doing some stuff with the size
pass
viewmenu = Menu(menubar, tearoff=0)
viewmenu.add_command(label="fg color", command="")
viewmenu.add_command(label="bg color", command="")
font_submenu = Menu(viewmenu,tearoff=0)
# Problem: Below 'for' loop creating huge height sub menubar
for size in range(2, 86, 2):
font_submenu.add_command(label=str(size), command=font_size(size))
viewmenu.add_cascade(label="Font", menu=font_submenu, underline=1)
menubar.add_cascade(label="View", menu=viewmenu)
root.config(menu=menubar)
root.mainloop()
提前致谢