how get no border effect in tkinter ttk?

前端 未结 2 2000
死守一世寂寞
死守一世寂寞 2021-01-25 07:31

\"enter

To get button no border effect in tkinter tk I used to set borderwidth=0

相关标签:
2条回答
  • 2021-01-25 08:03

    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()
    
    0 讨论(0)
  • 2021-01-25 08:15

    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.

    0 讨论(0)
提交回复
热议问题