Change border color and size Tkinter Menu

4

Can anyone help me with this question?

    
asked by anonymous 13.10.2016 / 13:36

2 answers

1

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

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

Then, given the image above, we will create a menu window with black background in the menu 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 change "tkinter" to "Tkinter" at all points)

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

file_menu.entry_config(0, ...)

Where 0 is the index of the desired entry.

    
30.01.2018 / 14:40
0

To change the size of the border you use 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 do not know if you can change.

    
29.10.2016 / 02:02