更改样式时IndexError超出范围

时间:2015-02-08 21:50:12

标签: python tkinter ttk indexoutofrangeexception

到目前为止,在我编写的一个程序中,我已经使用了基本的tkinter来构建小部件。然而,经过一些谷歌搜索,我发现了ttk及其主题小部件。

根据Python Docs网站上的documentation,我只需添加from tkinter.ttk import *即可使用ttk小部件而无需更改任何代码,因此对我来说似乎是值得的。

当然,唯一不起作用的是-bg标志。但是,当我尝试使用ttk样式时,我得到:

IndexError: list index out of range

所有的事情,虽然我在代码中没有写任何内容,而是引用了范围

这是代码的特定部分:

style = Style()
# stuff
style.map("rbstyle", background="grey")
# stuff
crBox = Label(win, width=6, textvariable=cr, 
              state='normal', relief='sunk', style="rbstyle")

这是输出:

Traceback (most recent call last):
  File "C:\Users\James\Google Drive\Queens' Athletics\window.py", line 83, in <module>
    style.map("rbstyle", background="grey")
  File "C:\Python34\lib\tkinter\ttk.py", line 402, in map
    self.tk.call(self._name, "map", style, *(_format_mapdict(kw))))
  File "C:\Python34\lib\tkinter\ttk.py", line 111, in _format_mapdict
    _format_optvalue(_mapdict_values(value), script)))
  File "C:\Python34\lib\tkinter\ttk.py", line 85, in _mapdict_values
    state[0] # raise IndexError if empty
IndexError: list index out of range
>>>

为什么我会出现此错误?我完全遵循它在Python Docs上所说的内容。

0 个答案:

没有答案