简体   繁体   中英

how get no border effect in tkinter ttk?

在此处输入图片说明

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM