Change color and border size Tkinter Menu

Asked

Viewed 2,075 times

3

Preciso diminuir a espessura da borda e a cor do Menu

Can someone help me with this question?

2 answers

2

The menu edge color is given by the background color (background) of the menu. If you want the border color to be different from the menu background color, you have to set the background color of each entry separately.

For edge thickness, simply set the value in pixels in the attribute "border", and the type of relief "flat" so that Tkinter does not create a pseudo-3D with the given color.

So, given the image above, let’s create a menu window, black menu background and red border:

import tkinter

def command():
    pass

def main():
    w = tkinter.Tk()
    menu = tkinter.Menu(w, background="black", foreground="red")
    file_menu = tkinter.Menu(menu, background="red", foreground="red", relief="flat", border=8, tearoff=0)
    opcoes = "Contas User  Usuários  Email Services  Login Cad. Usuário  Variáveis do Sistema  Sair".split("  ")
    for opcao in opcoes:
        file_menu.add_command(label=opcao, command=command, background="black")
    menu.add_cascade(label="Cadastro", menu=file_menu)

    w.config(menu=menu)
    return w

main()
tkinter.mainloop()

(this code is for Python 3 - in Python 2 just exchange "Tkinter" for "Tkinter" at all points)

If you want to change the background color or some other attribute of a menu entry after it is created, use the method in the menu:

file_menu.entry_config(0, ...)

Where 0 is the desired input index.

0

To change the size of the Voce border uses the borderwidth option in the Frame, you can also use Relief for the type of border ex:

Frame(ondevaioframe, relief = RIDGE, borderwidth = '8')

Now the color, I can’t tell you if it has to change.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.