【发布时间】:2019-12-03 21:26:51
【问题描述】:
我目前正在从事一个学校项目,该项目记录公司的员工信息并根据员工可用性、工作角色等因素生成轮班表。
为了记录员工假期,我使用了 TkCalendar 模块,它有自己的 Calendar 和 DateEntry 对象,可用于显示 GUI 日历信息。但是,我最近更换了计算机,并且用于允许用户在假期中添加的一段代码不再起作用;看来,当尝试创建第二个 DateEntry 对象时,TkCalendar 引发了一个错误,这似乎暗示我传递给第二个对象的选项无效。这令人困惑,因为第一个 DateEntry 对象似乎生成得很好。以下是我遇到的问题的测试用例示例:
from tkinter import *
from tkcalendar import DateEntry
class TestApp:
def __init__(self, root):
self.root = root
self.window = Frame(self.root)
self.window.pack()
self.label, self.calendar = [], []
self.font = ('Impact Bold', 13, 'bold')
labels = ['Select start date:', 'Select end date:']
for i in range(2):
self.label.append(Label(self.window, text=labels[i], font=self.font))
self.label[-1].grid(row=i+1, column=0)
self.calendar.append(DateEntry(self.window, font=self.font, locale='en_GB', width=15))
self.calendar[-1].grid(row=i+1, column=3)
if __name__ == '__main__':
root = Tk()
app = TestApp(root)
root.mainloop()
这会产生以下异常:
Traceback (most recent call last):
File "C:\Users\xav\Documents\Python files\TkCalendar DateEntry test case.py", line 24, in <module>
app = TestApp(root)
File "C:\Users\xav\Documents\Python files\TkCalendar DateEntry test case.py", line 18, in __init__
self.calendar.append(DateEntry(self.window, font=self.font, locale='en_GB', width=15))
File "C:\Users\xav\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\dateentry.py", line 105, in __init__
self._setup_style()
File "C:\Users\xav\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\dateentry.py", line 160, in _setup_style
self.style.map('DateEntry', **maps)
File "C:\Users\xav\AppData\Local\Programs\Python\Python38\lib\tkinter\ttk.py", line 403, in map
self.tk.call(self._name, "map", style, *_format_mapdict(kw)),
_tkinter.TclError: Invalid state name r
可以在here 找到 TkCalendar 文档。提前感谢您的帮助!
【问题讨论】:
-
我认为您的新计算机使用的是 python 3.8,而您之前可能使用的是旧版本。因此,您现在遇到了错误github.com/j4321/tkcalendar/issues/61。你可以尝试使用蛤蜊主题并告诉我你是否还有错误?
标签: python-3.x tkinter tkcalendar