how to know all style options of a ttk widget

前端 未结 3 1233
孤城傲影
孤城傲影 2020-12-30 03:45

This problem nearly makes me craze. I am a new beginner and without knowledge of tck/tk. I have done carefully search on the internet but haven\'t found a good solution.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 04:32

    The issue is that if you really want to control a style in detail you need to use the layout. So first identify the widget class using:

    >>b=ttk.Button(None)
    >>b.winfo_class()
    'TButton
    

    Then use the command

    >>> s.layout('TButton')
    [("Button.border", {"children": [("Button.focus", {"children": 
    [("Button.spacing",
    {"children": [("Button.label", {"sticky": "nswe"})], "sticky": "nswe"})], 
    "sticky": "nswe"})], "sticky": "nswe", "border": "1"})] 
    

    Finally change what you want:

    s.layout("MYButton.TButton",[("Button.border", {"children": 
    [("Button.focus", {"children": [("Button.spacing", {"children": 
    [("Button.label", {"sticky": "nswe"})], "sticky": "nswe"})], "sticky": 
    "nswe"})], "sticky": "we", "border": "1"})]
    

    This made the trick for me and finally provides me a way to control my ttk widget!!!

    Luca

提交回复
热议问题