I have a ttk Entry which is in "disabled" state.
The background color of the entry field while disabled is a light blue shade.
How can i change it to the default grey color? From this post i understood how we can change the foreground color.
tkinter ttk Entry widget -disabledforeground
I tried the same method for background color and it did not work.
I am using python 2.7 in Windows 7.
This is the code i tried as per the above said post:
from Tkinter import *
from ttk import *
root=Tk()
style=Style()
style.map("TEntry",background=[("active", "black"), ("disabled", "red")])
entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()
entry_var.set('test')
root.mainloop()
You don't need to use styles. You can change the color of disabled entry with option disabledbackground=<color>. You can use this option when creating the entry , like:
entry.config(background="black",disabledbackground="red")
So you overall code(Example) is:
from tkinter import *
import time
root=Tk()
entry=Entry(root,state='disabled')
entry.config(background="black",disabledbackground="red")
entry.pack()
root.mainloop()
Here is a screenshot of the GUI:
In ttk and Tk entries widgets, background refers to different things. In Tk Entry, background refers to the color behind the text, in ttk entry, background refers to the color behind the widget. (Yes, I know, confusing right?), what you want to change is fieldbackground. So your code would be
from Tkinter import *
from ttk import *
root=Tk()
style=Style()
style.map("TEntry",fieldbackground=[("active", "black"), ("disabled", "red")])
entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()
entry_var.set('test')
root.mainloop()
Related
I tried to change the default treeview border color using the highlightbackground option but it didn't work (my OS is Windows 10). here is an example:
from tkinter import *
from tkinter import ttk
parent=Tk()
style=ttk.Style()
style.configure("Treeview", highlightbackground="#red") # it doesn't work!!
TreeView = ttk.Treeview(parent)
TreeView.pack()
parent.mainloop()
How can I reach my goal?
How can I remove the dotted black border after a button is clicked in Tkinter (with Ttkthemes)?
I'm on Windows 10, Python 3.7.9.
There seems to be no uniform way to remove it and I searched across Google and SO with no luck. Thanks.
Here's a minimal example:
import tkinter
import tkinter.ttk
from ttkthemes import ThemedTk
tk = ThemedTk(theme="arc")
tk.configure(background="#f5f6f7")
tk.resizable(0,0)
selectFileInput = tkinter.ttk.Button(
tk,
text="Select Input File"
)
selectFileInput.place(x=20,y=60)
tk.mainloop()
I found the solution. It was to create a dummy button and focus it to remove focus from the button to the dummy button by using dummy.focus()
ttk.Button has the keyword argument takefocus this can be set to false and the button does not take focus after it is clicked.
ttk.Button(.., .., takefocus=False)
Therefore you do not need a hack with a dummy button that takes focus as in the answer.
I have a checkbox that works fine with the defaults values:
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import *
chk1 = Checkbutton(self , text=' 0 ', var=_Ch1_ )
chk1.grid(column=4, row=1)
When I try to add any option like "height = 5" I get the error:
_tkinter.TclError: unknown option "-height"
init.py lione 2299
This is because tkk.Checkbutton does not support height. You might want to use normal Checkbutton instead of ttk.Checkbutton. In your example you've said from ttk.tkinter import * which means ttk.Checkbutton becomes Checkbutton but not same as tk.Checkbutton
But anyway keep in mind, this height option wont make the checkbutton bigger, itll just give space other widgets '10'(or whatever) pixels away from it, just like pady
Read more
I am new to tkinter.
My code likes this,
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win)
Text.pack(padx=10,pady=10)
Win.mainloop()
As you can see,it only have the left border,top border.
However,it haven't right border and bottom border.
I have watched this How to set border color of certain Tkinter widgets?.
And I have tried highlightbackground=color,
the code is this
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win)
Text.config(highlightbackground="black")
Text.pack(padx=10,pady=10)
Win.mainloop()
it also didn't work.it made no difference.
In this document:tkinter.scrolledtext — Scrolled Text Widget,I know that the constructor is the same as that of the tkinter.Text class.And I have seen The Tkinter Text Widget,But it didn't have config about the tkinter.Text border.
What should I do?
it only have the left border,top border.
Because the widget config is relief="sunken",
So you can try relief="solid".
So this is may solve your problem
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win,relief="solid")
Text.pack(padx=10,pady=10)
Win.mainloop()
When I create a button like this in tkinter:
self.submition_button=Button(self.root, text='Submit',
font='Times 12 bold italic', command=self.onSubmition, bg='blue')
the button isn't blue.
Why isn't it blue, and what can I do to make it blue?
Are you using tkinter.Button or are you really using ttk.Button?
You'll know which one your using based on what you imported in the top of code
regular tkinter widgets importing
import tkinter
typical TTK widgets importing
from tkinter import ttk
Because TTK is more modern version of the library it's styling system is different. So setting flag options on it wont work. instead you have to use style theme.
See this reply.
https://stackoverflow.com/a/44416355/8661716
This is the code for a blue button, check it :
from tkinter import *
#create a window
root =Tk()
button=Button(root, text='Submit', font='Times 12 bold italic', bg='blue', activebackground="blue")
button.pack()
root.mainloop()