I am trying to change the focus color of a ttk.Entry widget in python (blue border):
I know that we can change the focus color of the notebook tabs with style.configure('Tab', focuscolor='red'), so I wonder how to do it with an entry widget?
Here is my code:
import tkinter
from tkinter import ttk
root = tkinter.Tk()
style = ttk.Style()
style.theme_use('clam')
style.configure('TEntry', focuscolor='red') # don't work
ttk.Entry(root).grid(padx=10, pady=10)
root.mainloop()
As suggested by #Thingamabobs and #acw1668 It's possible to change the focus color of a ttk.Entry by mapping the focus state in its style property. Here is the working code:
import tkinter
from tkinter import ttk
root = tkinter.Tk()
style = ttk.Style()
style.theme_use('clam')
style.map('TEntry', lightcolor=[('focus', 'white')])
ttk.Entry(root).grid(padx=10, pady=10)
root.mainloop()
My final goal was to hide the focus border so I changed its color to white (the background color), and now the result looks like this: (The black border is just the original border of the entry)
Related
Problem
My problem is that I need to remove the border for the ttk notebook. I am using ttk as a way of using multiple screens and I have removed the tabs from the notebook by doing: style.layout('TNotebook.Tab', []) but when I did that there is this ugly white border around the notebook this is what it looks like:
I am new to ttk so I do not know much about styling in the ttk module
So how can I remove the ugly white border of the notebook
I had a similar situation and wanted to remove the border surrounding Tkinter Notebook. Based on the suggestion from the comment #acw1668, I was able to remove the border. I post this answer incase it would help someone with similar problem.
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("400x300")
style=ttk.Style()
style.layout("TNotebook", [])
style.configure("TNotebook", highlightbackground="#848a98",tabmargins=0)# borderwidth = 0, highlightthickness = 0)
MainNotebook = ttk.Notebook(root, style="TNotebook")
MainNotebook.place(x=16, y=16)
Frame1=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame1.pack()
Frame2=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame2.pack()
MainNotebook.add(Frame1, text="Tab1")
MainNotebook.add(Frame2, text="Tab2")
root.mainloop()
I want to change the foreground and background colors of each item of the ComboBox in tkinter. I've found this post to change the color of the background dropdown menu and with the help of the answer there, i am able to change the forground of items with root.option_add("*TCombobox*Listbox*Foreground", 'red') but all are changing whereas i want to change them separately to a the different foreground and background colors, is it possible?
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.option_add("*TCombobox*Listbox*Foreground", 'red')
combo = ttk.Combobox(root, values=[i for i in range(10)]).pack()
root.mainloop()
You cannot change the color of individual items in a combobox dropdown menu.
I'm working on my GUI with python ttk; and I have this problem where the "check" on my ttk checkbuttons won't show with my style, so there's no way to know if it's activated or not. I've tried changing different style options, but I can't find any such option for the "default" theme.
I do not want to change my theme as that would ruin my other styles.
How can I change the makeup and layout of a ttk checkbutton?
from tkinter import ttk
tk = Tk()
style = ttk.Style()
style.theme_use('default')
ttk.Checkbutton(tk, text='hello there').grid()
I've been trying to learn Tkinter and subsequently ttk to create a GUI. When working with ttk I noticed something peculiar happening. When I gave any colour in an ARGB format, '#80FFFFFF' for example, there was no error but the particular widget simply turned into a small square. Why does this happen?
Here is an example,
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
s = ttk.Style()
s.configure('b1.TButton', background='#FF0000')
s.configure('b2.TButton', background='#80FFFFFF')
b1 = ttk.Button(root, style='b1.TButton')
b2 = ttk.Button(root, style='b2.TButton')
b1.grid()
b2.grid()
root.mainloop()
This is the result of this code:
Tkinter buttons do not support transparency so my thoughts is that the extra FF in your ARGB code that tells the color to be transparent is what is causing the issue.
My guess from my research is that the Button cannot format properly due to the transparency color code and thus causes this problem when displaying the button.
You can test this by adding FF to any ARGB color and see the same effect.
When I disable a button the color change automatically to black.
This is the code :
from tkinter import *
from tkinter import ttk
root=Tk()
style=ttk.Style()
style.configure('TButton', foreground='red')
bu1=ttk.Button(root, text="Hello world")
bu1.grid(row=0, column=0)
bu2=ttk.Button(root, text="Hello world2")
bu2.grid(row=1, column=0)
bu1.state(['disabled'])
bu2.state(['disabled'])
root.mainloop()
Any help?
Since you are using a ttk button, you can map certain attributes to different button states with the map method of the style object.
For example, to change the colors when the button state is "disabled", you can set the color like this:
style.map(
"TButton",
foreground=[("disabled", "black")]
)
For more information see 50.2. ttk style maps: dynamic appearance changes on the New Mexico Tech tkinter documentation, and also Styles and Themes on tkdocs.com