[pygtk] gtk.Calendar: IN A DIALOG?
skip at pobox.com
skip at pobox.com
Mon Apr 7 00:08:58 WST 2008
Luis> you can use time module and use the localtime function, take the
Luis> localtime and set it in the gtk.Calendar, it's would be something
Luis> like this:
...
Not directly related to the task at hand, but anytime I need to do any sort
of date arithmetic these days I much prefer to use the datetime module. The
equivalent of time.localtime() usage would be
import datetime
now = datetime.datetime.now()
calendar.select_month(now.year, now.month-1)
calendar.select_day(now.day)
This particular example doesn't highlight datetime's advantages, but if you
want to do simple date arithmetic it becomes immediately obvious that it is
easier to use:
now = datetime.datetime.now()
week_ago = now - datetime.timedelta(days=7)
whereas with the time module everything is done in float and you have to
convert back and forth between float and tuple representations all the time.
In addition, the useful range of datetime objects is much greater than the
current 32-bit float representation.
--
Skip Montanaro - skip at pobox.com - http://www.webfast.com/~skip/
More information about the pygtk
mailing list