Python Forum
[Tkinter] Tkinter custom widget styling and creating custom theme
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter custom widget styling and creating custom theme
#1
I would like to create a custom theme for my app. I can't get the button widget to expand in my code below. I can configure the button using the minimum width parameter but it should expand to fit the text as specified under layout.
Any ideas what is wrong with the code below?

    import tkinter
    from tkinter import ttk
    root = tkinter.Tk()
    colors = {
              "frame": "#efefef",
              "disabledfg": "#aaaaaa",
              "selectbg": "#657a9e",
              "selectfg": "#ffffff"
             }
    style = ttk.Style()
    style.theme_create("test", "default", settings={
        ".": {
            "configure":
                {"background": colors['frame'],
                 "troughcolor": colors['frame'],
                 "selectbackground": colors['selectbg'],
                 "selectforeground": colors['selectfg'],
                 "fieldbackground": colors['frame'],
                 "font": "TkDefaultFont",
                 "borderwidth": 1},
            "map": {"foreground": [("disabled", colors['disabledfg'])]}
        },
        "TButton": {
                    "configure": {"width": 10, "anchor": "left"},
                    "layout": [
                        ("Button.button", {"children":
                            [("Button.focus", {"children":
                                [("Button.padding", {"children":
                                    [("Button.label", {"side": "left", "expand": 1})]
                                })]
                            })]
                        })
                    ]
                }})
    style.theme_use("test")
    button_send = ttk.Button(root, text="TEST BUTTON ONLY!").grid(row=0, column=0, padx=50, pady=50)
    root.mainloop()
Reply


Messages In This Thread
Tkinter custom widget styling and creating custom theme - by karolp - May-05-2020, 07:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 846 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  neeed to activate a custom tk slider janeik 1 830 Oct-09-2023, 09:29 AM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,837 Jun-26-2022, 06:26 PM
Last Post: menator01
  Tkinter Exit Code based on Entry Widget Nu2Python 6 2,982 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  Creating a function interrupt button tkinter AnotherSam 2 5,512 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [TKINTER] Problems creating directories in a selected path Vulera 2 2,763 Aug-10-2021, 06:38 PM
Last Post: Vulera
  tkinter text widget word wrap position chrisdb 6 7,556 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  [Tkinter] Change property of custom Object Sancho_Pansa 0 1,432 Dec-17-2020, 10:53 AM
Last Post: Sancho_Pansa
  How to disable custom button Sancho_Pansa 7 3,484 Dec-04-2020, 02:21 PM
Last Post: buran
Question [PyQt] CSS Styling for a QLabel inside a QListWidget Alfalfa 2 5,137 Nov-30-2020, 02:59 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020