0

用于ttk.Checkbutton.instate('selected') 获取 a 的当前状态checkbutton给我这个错误:

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

这是我的代码:

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()

代码现在应该可以工作了。ck.instate('selected) 给出错误并且似乎只看到参数的第一个字符

4

0 回答 0