Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get rid of white border around option menu

I'm trying to get rid of the white border around the OptionMenu.

What I tried

I changed the colour to red, but there is still a white border around it.

Can anyone help?

enter image description here

Here's the code:

from tkinter import *
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('500x500')
var = StringVar()
option = ttk.OptionMenu(root,var,'1','2','3')
option["menu"].config(bg="red")
option.pack()
root.mainloop()

Also, is there a way to change the colour of the OptionMenu trigger box (In the red Circle)? enter image description here

like image 526
coderoftheday Avatar asked Jun 08 '20 19:06

coderoftheday


People also ask

How to remove thick highlight border from focused items in Windows 10?

In right-side pane, scroll down and look for “ Use Narrator cursor ” section. Uncheck “ Show the Narrator cursor on the screen ” option. That’s it. It’ll remove the focus/highlight rectangle from selected items. You are here: Home » Windows 10 » [Windows 10 Tip] Remove Thick Highlight Border from Focused Items

How do I get rid of the border around the keyboard?

I have attached some screenshots which should highlight the border that I'm referring to. Go to Settings > Ease of Access > Keyboard > Enable shortcut underlines and set to Off.

How to remove the focus/highlight rectangle from selected items in word?

3. In right-side pane, scroll down and look for “ Use Narrator cursor ” section. Uncheck “ Show the Narrator cursor on the screen ” option. That’s it. It’ll remove the focus/highlight rectangle from selected items.

What is the rectangular border on the menu bar?

The rectangular border shows on focused/highlighted items. For example, you are hovering mouse cursor over a menu, opening a program, etc. The border is not dotted but a solid line appears around the focused item. Following are some screenshots of the thick rectangular border:


Video Answer


1 Answers

As stated in the comments by @Mike-SMT,

Have you considered writing your own option menu?

This, to me, seems to be the only way to get an OptionMenu without having that irritating grey border.

Here is my attempt at it:

import tkinter as tk
root = tk.Tk()
root.geometry('500x500')

class custom_option_menu(tk.Tk):

    def down(self, *menu_items):
        if self.button["text"] == "↓":
            self.frame.place(x = self.x + (len(self.first) * 13)/2, y = self.y + 50, anchor = "center")
            self.button.config(text = "↑")

        elif self.button["text"] == "↑":
            self.frame.place_forget()
            self.button.config(text = "↓")

    def __init__(self, master, first, bg, *menu_items):

        self.master = master
        self.first = first
        self.menu_items = menu_items
        self.bg = bg
        self.frame = tk.Frame(master, height = 100, width = 100)
        self.otherframe = tk.Frame(master, height = 10, width = len(first) * 13)
        self.label = tk.Label(self.otherframe, text = str(first))
        self.button = tk.Button(self.otherframe, text = "↓", command = lambda: self.down(), relief= "flat")
        def save_var(event = "<Button-1>"):
            print(event.widget["text"])
        for i in range(len(self.menu_items)):
            self.frame.config(bg = self.bg)
            self.option = tk.Button(self.frame, text = self.menu_items[i], relief = "flat", bg = self.bg, textvariable = int(i))
            self.option.pack()
            self.option.bind("<Button-1>", save_var)





    def put(self, x, y):
        self.x = x
        self.y = y
        self.button.pack(side = "right")
        self.label.pack()
        self.frame.place(x = x + (len(self.first) * 13)/2, y = y + 50, anchor = "center")

        self.frame.place_forget()
        self.otherframe.place(x = x + (len(self.first) * 13)/2, y = y, anchor = "center")

nice = custom_option_menu(root, "o000000000000000", "blue", "First", "second", "Third")
nice.put(100, 200)
root.mainloop()

Sadly I couldn't get the default geometry managers to work for this, so I created .put(). It's just the x and y coordinates.

The arguments to the class custom_option_menu go as follows:

  • The first argument is the parent widget.
  • The second argument is the text on the OptionMenu.
  • The third argument is the background color for the options.
  • The remaining arguments are the options.
  • To open the menu, click the down arrow.

    I hope this is what you were looking for!

    like image 51
    10 Rep Avatar answered Oct 11 '22 22:10

    10 Rep