【发布时间】:2020-03-02 21:14:14
【问题描述】:
我正在创建一个从用户那里获取日期的程序,现在我需要转换为字符串,因为我需要将这些数据放入我正在实现的命令 shell 中,使用 tkinter 和 tkcalendar(lib 为我提供进入)。 我该怎么做?
这里是我要在 git 上运行的代码:
cal = Calendar(top, font='Arial 14', selectmode='day', cursor='hand1')
subprocess.call('git log --pretty='"format: % h"' --after=' +cal+' --before='+cal, shell=True)
【问题讨论】:
-
@wjandrea 我试过了,这是终端的例外:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "window.py", line 29, in calendar cal.strtime('%Y/%m/%d')+' --before='+cal.strtime('%Y/%m/%d'), shell=True) AttributeError: 'Calendar' object has no attribute 'strtime' -
你需要使用
Calendar对象的datetime属性,然后是strftime,而不是strtime -
很抱歉,但是,看起来:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "window.py", line 28, in calendar subprocess.call('git log --pretty='"format: % h"' --after=' + cal.datetime.strftime( TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'str' object
标签: python python-3.x tkinter