[英]How to style border for one side in ttk widgets? Tkinter
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?
我想知道如何设置主题 Tkinter 小部件的边框一侧,特别是按钮或 TButton?
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.