ttk.Widget.state() TclError: Invalid state name
<p>I try change ttk.button state (at the beggining of mainloop) in tkinter like in this <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Widget.html" rel="nofollow">manual</a> [actualization: actually <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-state-spec.html" rel="nofollow">here</a>.]</p>

<pre><code>import tkinter
from tkinter import ttk

root = tkinter.Tk()

style = ttk.Style()
style.map("C.TButton",
    foreground=[('pressed', 'red'), ('active', 'blue')],
    background=[('pressed', '!disabled', 'black'), ('active', 'white')]
    )

colored_btn = ttk.Button(text="Test", style="C.TButton")
colored_btn.pack()

colored_btn.state('pressed')

root.mainloop()
</code></pre>

<p>Result in error:</p>

<pre><code>in state return self.tk.splitlist(str(self.tk.call(self._w, "state", statespec))) _tkinter.TclError: Invalid state name p
</code></pre>

<pre><code>colored_btn.state(('pressed',))
</code></pre>

<p>From <a href="https://docs.python.org/3.4/library/tkinter.ttk.html?highlight=ttk%20style#tkinter.ttk.Widget.state" rel="nofollow">Python Documentation</a>:</p>

<blockquote>
  <p>statespec will usually be a list or a tuple.</p>
</blockquote>

<p>I suppose this issue comes from 8.6 vs 8.5 tkinter version difference.</p>

<p>Take notice that in manual linked in question (tkinter 8.5) there is <code>stateSpac</code> argument and in tkinter 8.6 - <code>statespec</code>. Such things should always warn you that there may be changing in versions.</p>

python tkinter tk ttk