ARGB in tkinter ttk behaves unexpectedly - python

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.

Related

Change ttk Entry focus color - Python

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)

How to Design the Scrollbar in tkinter (not ttk ones)

I have tried to design the tkinter's Scrollbar instead of using ttk ones.
But I couldn't be able to implement designs on the scrollbar. I think I have implemented the same config options as in the effbot docs.
from tkinter import *
testing=Tk()
a=Listbox(testing,height=6)
sc=Scrollbar(testing,orient=VERTICAL,command=a.yview)
for i in range(100):
a.insert(END,i)
a.config(yscrollcommand=sc.set)
def designs():
# This function does nothing :(
sc.config(background='orange',borderwidth=34)
sc.config(highlightthickness=30,highlightcolor='orange',highlightbackground='skyblue')
sc.config(troughcolor='orange')
designs() # here...
sc.pack(side=RIGHT,fill=Y)
a.pack()
testing.mainloop()
is there a way to change the background color of the trough part and non-trough part of the scrollbar and some effects like the active background? Please Help!!!

Is it possible to fit a special size for tkinter window?

I use tkinter in python and I want to fix the size of a window in tkinter for always it means that if user wants to change it by restore button the window size not changed.
from tkinter import *
root=Tk()
root.geometry("1800x900")
root.mainloop()
I'm not sure I've fully understood your question, but to enforce a fixed window size I've used to set min and max to the same value, as follows.
from Tkinter import Tk
root=Tk()
fixed_geometry=180,90
root.minsize(*fixed_geometry)
root.maxsize(*fixed_geometry)
root.mainloop()

tkinter topmost and overridedirect

I want to write a program with a window set to always at the top and without the border. So I write the following program, which doesn't work as intended (macOS Sierra, 10.12.3):
import tkinter as tk
root=tk.Tk()
tk.Label(root,text='some text').pack()
root.attributes('-topmost',True)
root.overrideredirect(1)
root.mainloop() #this one doesn't work
screenshot of the failed one
However, when I change the sequence of overridedirect and attributes, surprisingly it worked.
import tkinter as tk
root=tk.Tk()
tk.Label(root,text='some text').pack()
root.overrideredirect(1)
root.attributes('-topmost',True)
root.mainloop() #this one works
screenshot of the successful one
Can someone please tell me why the sequence of those two lines matters?

Issue with Scale widget using tickinterval

The widget shows tick using tickinterval when following code shown below,
from Tkinter import *
slider_1 = Scale(mGui,orient=HORIZONTAL,length = 100,from_=0,to=9, tickinterval =1).pack()
However it throws error with the following code
from Tkinter import *
from ttk import *
slider_1 = Scale(mGui,orient=HORIZONTAL,length = 100,from_=0,to=9, tickinterval =1).pack()
Error:
_tkinter.TclError: unknown option "-tickinterval"
Why is it so? Is it a bug or problem with the installation. For information i am using Python 2.7.10
This is because the ttk module contains also a Scale widget, and you are actually using the Scale widget from ttk and not from Tkinter. Widgets in the ttk module are customised and styled differently from Tkinter widgets.
Check the following documentation on ttk for more information regarding its widgets:
ttk — Tk themed widgets
To solve your problem, you could remove your second global import and simply do:
import ttk
Then, every time you want to use a widget from ttk, you can simply prefix it with ttk..

Categories

Resources