Я работаю с Tkinter и guizero и пытаюсь стилизовать строку меню. Я использую Python 3.8.2
То, что я пытаюсь изменить
Удалите границу / 3D-эффект в строке меню и параметрах.
Удалите прокладку верхней панели меню (небольшое пространство сверху и слева).
Активный выбор цвета как для верхнего уровня / строки меню, так и для параметров.
from guizero import App, MenuBar
def file_function():
print("File option")
def about_function():
print("about option")
app = App(title="My app", height=300, width=500,bg='white')
menubar = MenuBar(app,
toplevel=["File", "About"],
options=[
[ ["New", file_function], ["Save", file_function]],
[ ["Report Bug", about_function], ["About", about_function] ]
])
menubar.bg=(111, 77, 124)
# none of the styling below works and this is what I've tried
menubar.border=0
menubar.toplevel.border=False
menubar.options.border=0
menubar.toplevel.options.bg='gray'
menubar.toplevel.focus.bg='yellow'
menubar.toplevel.focus.fg='yellow'
menubar.toplevel.options.border=False
app.display()
Изображение:
Обновить
В настоящее время меню не предназначено для того, чтобы хорошо выглядеть, странные цвета предназначены для того, чтобы увидеть, что работает, а что нет. Я могу использовать виджет Guizero и все их функции.
Текущие проблемы
- Невозможно удалить трехмерный / возможный эффект заполнения в меню и подменю, когда выбран элемент
Я пробовал установить границу на 0 и высоту выделения на 0
Обновленный код
from guizero import *
from tkinter import *
app=App(title='Test',bg=(53, 60, 81))
root = app.tk
def hello():
print ("hello!")
#creates menubar
menubar = Menu(root,relief=FLAT,bd=0)
# Sets menubar background color and active select but does not remove 3d effect/padding
menubar.config(bg = "GREEN",fg='white',activebackground='red',activeforeground='pink',relief=FLAT)
# First item on menubar and creates sub options
filemenu = Menu(menubar, tearoff=0,relief=FLAT, font=("Verdana", 12),activebackground='red')
filemenu.config(bg = "GREEN")
filemenu.add_command(label="New (Ctrl + N)", command=hello)
filemenu.add_command(label="Save(Ctrl + S)", command=hello)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
# Adds to menubar and creates sub options
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=hello)
editmenu.add_command(label="Copy", command=hello)
editmenu.add_command(label="Paste", command=hello)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0,bg='green',fg='blue')
helpmenu.add_command(label="Report bug", command=hello)
helpmenu.add_command(label="About", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.activebackground='red'
root.config(menu=menubar)
app.display()
guizero
- это пакет, унаследованный от tkinter, думаю, у вас не получилось. Вам нужно создать меню самостоятельно. - person jizhihaoSAMA   schedule 01.07.2020guizero
. К сожалению, у меня нет доступа к машине с Windows, поэтому я не могу найти решение. - person Saad   schedule 01.07.2020app.tk
какroot
- person Saad   schedule 01.07.2020