为了在 tkinter tk 中获得按钮无边框效果,我曾经设置 borderwidth=0
。按钮将合并到背景中。但我无法在 tkinter ttk 中获得相同的效果。我在样式中设置了 borderwidth=0
。按钮始终有边框宽度。不知道为什么?
最佳答案
您可以通过使用 ttk 样式将按钮浮雕设置为 flat
或将 borderwidth 设置为 0 来实现。但是,某些 ttk 主题不考虑这些样式设置,其中之一是 Windows 中的默认主题。将主题设置为“clam”或“alt”应该可以解决您的问题。
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()
关于python - 如何在 tkinter ttk 中获得无边框效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40990704/