I have a ttk.Separator widget and I would like it to be all black. I used ttk.Style() as follows
import Tkinter as TK
import ttk
self.line_style = ttk.Style()
self.line_style.configure("Line.TSeparator", background="#000000")
self.line = ttk.Separator(self.tk, orient=TK.VERTICAL, style="Line.TSeparator")
self.line.place(x = 1250,y = 0, height = self.tk.winfo_screenheight(), width = 8)
And the separator is black, 8 pixels wide, but it has a 1 pixel white line on the left side. Plase, do you know how could I get rid of it?
Unfortunately you can't get rid of the 1 pixel white line, the only available option to configure for a ttk Separator is the background
option. You can see this by finding the layout of the Separator and then listing all of its configuration options as follows
s = ttk.Style()
print(s.layout('TSeparator')) # [('Separator.separator', {'sticky': 'nswe'})]
print(s.element_options('Separator.separator')) # ('-orient', '-background')
If you set the background color to something other than black you'd see that this 1 pixel border is not always white but somehow related to chosen background color, either a lighter or darker shade.
The most viable workaround is to simply insert a styled Frame
(ttk or regular tkinter) of the desired width instead of using a separator
I know that this is an old post but I had the same issue and figured out a work around. When I create a 1 pixel high tkinter.Frame
and stretch it out along the x-axis, I get something that looks like a ttk.Separator
. Example:
import tkinter as tk
root = tk.Tk()
separator = tk.Frame(root, bg="blue", height=1, bd=0)
separator.pack(fill="x")
root.mainloop()
The colour of the separator is controlled by its bg
keyword.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.