Search code examples
pythontkinterborder

LabelFrame is faint


This simple code creates a LabelFrame with 4 labels inside it. The outline of the frame is very faint, and changing the borderwidth or color has not effect.

import tkinter as tk
from tkinter import *

import tkinter.ttk as ttk
from tkinter.ttk import *

root = tk.Tk()
# create LabelFrame  
labelframe = LabelFrame(root, text="State data", borderwidth=5)
labelframe.pack( pady=5)

# add 4 labels 
Label(labelframe, text="State").pack()
Label(labelframe, text="Abbrev").pack()
Label(labelframe, text="Capital").pack()
Label(labelframe, text="Founded").pack()

tk.mainloop()

enter image description here


Solution

  • Have you tried different values for the relief argument? SOLID leads to a very ... unfaint result on my machine:

    enter image description here

    Obtained with these settings:

    # create LabelFrame
    labelframe = LabelFrame(root, text="State data", borderwidth=5, relief=SOLID)
    labelframe.pack(padx=5, pady=5)
    

    Update:

    For Windows 10 the above settings are not enough. Verified on my machine as well. Python 3.7 and Python 3.8 are affected. It seems to be an issue with the default theme used on Windows machines.

    So you need to fiddle around with the Tkinter Style:

    import tkinter as tk
    from tkinter import *
    from tkinter import ttk
    
    from tkinter.ttk import *
    
    root = tk.Tk()
    style = ttk.Style()
    
    print(f"available themes: {', '.join(style.theme_names())}")
    style.theme_use('alt')
    
    labelframe = LabelFrame(root, text="State data", borderwidth=4, relief=SOLID)
    labelframe.pack(padx=5, pady=5)
    
    Label(labelframe, text="State").pack()
    Label(labelframe, text="Abbrev").pack()
    Label(labelframe, text="Capital").pack()
    Label(labelframe, text="Founded").pack()
    
    if __name__ == "__main__":
        print("starting")
        tk.mainloop()
    

    That sample prints the available themes to the console. Try out, which one serves your needs best.

    The result for theme 'alt' is far from perfect but points in the right direction:

    enter image description here

    For more details about the styling, I suggest to consult the section about theme_settings in the manual.