TKinter Style & Treeview Click Issues

后端 未结 1 2031
离开以前
离开以前 2021-01-23 16:06

I am struggling with styles in TKinter My main problem is that you cannot click anything in the treeview.

To test, simply press the \"Press To Test\" Button

For

相关标签:
1条回答
  • 2021-01-23 16:37

    Question: cannot click anything in the treeview.
    Using .theme_create disables selected style in Treeview.


    Click is working, you can verify this by binding a callback to the event '<Button....

        def on_selected(event):
            print('on_selected{}'.format(event))
    
        t1.bind('<ButtonRelease-1>', on_selected)
    
    

    Reference:

    • widget.bind(event, handler)

      For each widget, you can bind Python functions and methods to events. If an event matching the event description occurs in the widget, the given handler is called with an object describing the event.


    You are loosing the 'selected' style or the '!selected' style becomes the same. Therefore no color change happens if you click at a Row.

    Solution:
    Set explicit a 'selected' style for the Treeview widget in your new theme.

    style.theme_create("fclassic", parent="alt",
                       settings={
                            'Treeview': {
                                'map': {
                                    'background': [('!selected', 'blue'), ('selected', 'red')],
                                    'foreground': [('selected', 'black')],
                                    'font': [('selected', ("Century Gothic", 10, 'bold'))],
                                }  # end 'map'
                            }  # end 'Treeview'
                       }  # end settings
                       )
    

    Reference:

    • Changing Widget Colors

      collect all the information on setting the colors of modern widgets


    Tested with Python: 3.5 - 'TclVersion': 8.6 'TkVersion': 8.6

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