Jim Robinson
Jim Robinson

Reputation: 199

ttk.Checkbutton instate failing

Using ttk.Checkbutton.instate('selected') to get current state of a checkbutton gives me this error:

File "C:\Program Files\Python\lib\tkinter\ttk.py", line 576, in instate
 self.tk.call(self._w, "instate", ' '.join(statespec)))_tkinter.TclError: Invalid state name s

This is my code:

import tkinter as tk
from tkinter import ttk
def p(event):
    st = ck.state()
    if 'selected' in st:
        print ('got selected')
    if ck.instate('selected') :
        print('instate true')       
root = tk.Tk()
root.geometry('200x200+300+200')
root.grid_rowconfigure(0, weight = 1)

ck = ttk.Checkbutton(root,text = 'tryme')
ck.grid()
root.bind('<Return>',p)
root.mainloop()

The code should work now. ck.instate('selected) gives error and appears to only see the first character of the argument

Upvotes: 0

Views: 421

Answers (0)

Related Questions