TkinterEP / ttkwidgets

A collection of widgets for Tkinter's ttk extensions by various authors
GNU General Public License v3.0
137 stars 28 forks source link

ttkwidgets.Table rise '_tkinter.TclError' when use some 'Style' on Windows environment. #69

Closed water5 closed 3 years ago

water5 commented 3 years ago

Test environment: Windows 8.1, Python3.9.0

style = ttk.Style(root) style.theme_use('xpnative')

'winnative', 'vista', 'xpnative' Style works fine, 'clam', 'alt', 'default', 'classic' Style rise Error below:

Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Python39\lib\site-packages\ttkwidgets-0.11.0-py3.9.egg\ttkwidgets\table.py", line 68, in >init self._initialize_style() File "C:\Program Files\Python39\lib\site-packages\ttkwidgets-0.11.0-py3.9.egg\ttkwidgets\table.py", line 122, in _initialize_style style.map('Table', *style_map) File "C:\Program Files\Python39\lib\tkinter\ttk.py", line 403, in map self.tk.call(self._name, "map", style, _format_mapdict(kw)), _tkinter.TclError: Invalid state name d

when create 'table' with: table = Table(root, columns=columns, sortable=sortable.get(), drag_cols=drag_col.get(), drag_rows=drag_row.get(),height=6)

melassa commented 3 years ago

I have the same problem under python 3.8, W7 running the table.py example without any change (the example set the 'alt' theme):

Traceback (most recent call last):
   table = Table(root, columns=columns, sortable=sortable.get(), drag_cols=drag_col.get(),
  File "C:\Python38\lib\site-packages\ttkwidgets\table.py", line 68, in __init__
    self._initialize_style()
  File "C:\Python38\lib\site-packages\ttkwidgets\table.py", line 122, in _initialize_style
    style.map('Table', **style_map)
  File "C:\Python38\lib\tkinter\ttk.py", line 403, in map
    self.tk.call(self._name, "map", style, *_format_mapdict(kw)),
_tkinter.TclError: Invalid state name d
RedFantom commented 3 years ago

I am unable to reproduce this issue on either Windows 10 with Python 3.9.1 or Windows 7 with Python 3.6.6 or Python 3.8.7. From the code, given the error, I would expect that somehow the style map is not formatted properly (particularly, there's a string where there should be a tuple), but I cannot see how this issue can occur with the style_map.

Is just running the example_table.py from the master branch without any change on a clean Python environment really sufficient to trigger this exception? Because I can't reproduce this exception when doing that...

melassa commented 3 years ago

C:\dev\python\ttkwidgets>py -3 -V
Python 3.8.6

C:\dev\python\ttkwidgets>py -3 -m pip check ttkwidgets
No broken requirements found.

C:\dev\python\ttkwidgets>py -3 examples\example_table.py
Traceback (most recent call last):
  File "examples\example_table.py", line 22, in <module>
    table = Table(root, columns=columns, sortable=sortable.get(), drag_cols=drag_col.get(),
  File "C:\Python38\lib\site-packages\ttkwidgets\table.py", line 68, in __init__
    self._initialize_style()
  File "C:\Python38\lib\site-packages\ttkwidgets\table.py", line 122, in _initialize_style
    style.map('Table', **style_map)
  File "C:\Python38\lib\tkinter\ttk.py", line 403, in map
    self.tk.call(self._name, "map", style, *_format_mapdict(kw)),
_tkinter.TclError: Invalid state name d

ttkwidgets version: 0.11.0

If i comment the line style.theme_use('alt') the program works.

melassa commented 3 years ago

This is the background of alt theme map:

        'background': [
            'disabled', '#d9d9d9', '!disabled !selected', '#ffffff', 'selected', '#4a6984'
        ]

And this is the native:

        'background': [
            ('disabled','SystemButtonFace'),
            ('!disabled', '!selected', 'SystemWindow'),
            ('selected', 'SystemHighlight')
        ]
RedFantom commented 3 years ago

That's most likely an issue on Windows then, as on Linux the style map, even for theme alt, always looks properly formatted. I am currently not in a position to test it, but I will add it to my todo list. That looks like it will make the parsing more complicated though, and that might even be a bug in Tkinter.

melassa commented 3 years ago

I think it is a tkinter bug:

tkinter alt Treeview map (Pyhon 3.8):

{
'foreground': [('disabled', '#a3a3a3'), ('!disabled', '!selected', 'black'), ('selected', '#ffffff')], 
'background': ['disabled', '#d9d9d9', '!disabled !selected', '#ffffff', 'selected', '#4a6984']
}

Tcl alt Treeview map (Python 3.8):

-foreground {disabled #a3a3a3 {!disabled !selected} black selected #ffffff} 
-background {disabled #d9d9d9 {!disabled !selected} #ffffff selected #4a6984}

I think it is more easy to edit the tcl output...

RedFantom commented 3 years ago

All right, so I've tried it now on Windows 10 with Python 3.9.1 and Python 3.8.7, and I cannot reproduce this error. The code for _splitdict, which parses the output of the Tcl command called by style.map() actually hasn't changed between these versions, so I'm not sure what's going wrong here.

@melassa What sub-versions of Python are using? Are you using the default CPython distributions from python.org? You are using Windows, right? Python 3.9.1 isn't available for Windows 7, so are you using two different versions of Windows or are you using 3.9.0?

melassa commented 3 years ago

It was a tkinter bug fixed in 3.8.7 (my bugged version was 3.8.6 under W7). You can close this issue.

RedFantom commented 3 years ago

Okay, great that you found the problem!