how get no border effect in tkinter ttk?

限于喜欢 提交于 2019-12-12 05:36:52

问题


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?


回答1:


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()



回答2:


You can't remove the border on windows or osx. The whole point of using ttk buttons on those platforms is to get native widgets. If you want a button without a border, use the standard tk button.



来源:https://stackoverflow.com/questions/40990704/how-get-no-border-effect-in-tkinter-ttk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!