My question is simple. I want to know how to style one border side of a themed Tkinter widget specifically a button or a TButton?
Asked
Active
Viewed 648 times
0
-
What is your expected output? – May 22 '21 at 15:51
-
@Sujay my expected output is a button or a frame with border color of one side – Zues May 22 '21 at 15:52
-
So you want only one side pf your frame with different colour – May 22 '21 at 15:53
-
@Sujay yes I want one side of the border to be color for my button yes – Zues May 22 '21 at 15:56
1 Answers
1
Check this? It is a modified version
from tkinter import *
from tkinter import ttk
class MyLabel(Frame):
'''inherit from Frame to make a label with customized border'''
def __init__(self, parent, myborderwidth=0, mybordercolor=None,
myborderplace='center', *args, **kwargs):
Frame.__init__(self, parent, bg=mybordercolor)
self.propagate(False) # prevent frame from auto-fitting to contents
self.button = ttk.Button(self, *args, **kwargs) # make the label
# pack label inside frame according to which side the border
# should be on. If it's not 'left' or 'right', center the label
# and multiply the border width by 2 to compensate
if myborderplace == 'left':
self.button.pack(side=RIGHT)
elif myborderplace == 'right':
self.button.pack(side=LEFT)
else:
self.button.pack()
myborderwidth = myborderwidth * 2
# set width and height of frame according to the req width
# and height of the label
self.config(width=self.button.winfo_reqwidth() + myborderwidth)
self.config(height=self.button.winfo_reqheight())
root=Tk()
MyLabel(root, text='Hello World', myborderwidth=4, mybordercolor='red',
myborderplace='left').pack()
root.mainloop()
-
This is something I am looking for but I want to do this for button and for TTK not normal tkinter – Zues May 22 '21 at 16:34