如何在tkinter ttk中获得无边框效果? [英] how get no border effect in tkinter ttk?

查看:702
本文介绍了如何在tkinter ttk中获得无边框效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要获得按钮在tkinter tk中没有边框效果,我曾经设置了borderwidth=0.按钮将合并到背景中.但是我无法在tkinter ttk中获得相同的效果.我设置了borderwidth=0的样式.按钮始终具有borderwidth.我不知道为什么?

To get button no border effect in tkinter tk I used to set borderwidth=0. Button will merge into background. But I can't get same effect in tkinter ttk. I set borderwidth=0 in style. Button always have borderwidth. I don't know why?

推荐答案

您可以通过使用ttk样式将按钮释放方式设置为flat或将borderwidth设置为0来实现所需的功能.但是,某些ttk主题没有考虑这些样式设置,其中之一是Windows中的默认主题.将主题设置为蛤"或替代"应该可以解决您的问题.

What you want can be achieved by setting the button relief to flat or borderwidth to 0 using a ttk style. However, some ttk themes don't take into account these style settings, and one of them is the default theme in Windows. Setting the theme to 'clam' or 'alt' should solve your problem.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

b1 = tk.Button(root, text='tk.Button', borderwidth=0)
b1.pack()

s = ttk.Style(root)
s.theme_use('clam')
s.configure('flat.TButton', borderwidth=0)
# s.configure('flat.TButton', relief='flat') gives the same result

b2 = ttk.Button(root, style='flat.TButton', text='ttk.Button')
b2.pack()

root.mainloop()

这篇关于如何在tkinter ttk中获得无边框效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆