Changing the appearance of a Scrollbar in tkinter (using ttk styles)

前端 未结 3 1340
南旧
南旧 2020-12-09 12:21

I was wondering if you could help me with a style options issue in ttk. I\'ve managed to change most of the basic ttk widgets to the style of my preference. I\'m only stuck

3条回答
  •  轮回少年
    2020-12-09 13:09

    It's easier if you use the clam theme:

    import tkinter as tk
    from tkinter import ttk
    
    root = tk.Tk()
    style = ttk.Style()
    style.theme_use('clam')
    
    # list the options of the style
    # (Argument should be an element of TScrollbar, eg. "thumb", "trough", ...)
    print(style.element_options("Horizontal.TScrollbar.thumb"))
    
    # configure the style
    style.configure("Horizontal.TScrollbar", gripcount=0,
                    background="Green", darkcolor="DarkGreen", lightcolor="LightGreen",
                    troughcolor="gray", bordercolor="blue", arrowcolor="white")
    
    hs = ttk.Scrollbar(root, orient="horizontal")
    hs.place(x=5, y=5, width=150)
    hs.set(0.2,0.3)
    
    root.mainloop()
    

提交回复
热议问题