I'm trying to get rid of the white border around the OptionMenu
.
I changed the colour to red, but there is still a white border around it.
Can anyone help?
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)?
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
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.
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.
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:
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:
OptionMenu
. To open the menu, click the down arrow.
I hope this is what you were looking for!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With