开发者

Insert date from wxdatepickerctrl to database

self.dateEntry = wx.GenericDatePickerCtrl(self, -1, size=(120,20), pos=(90,185),
                                       style = wx.TAB_TRAVERSAL
                                           | wx.DP_DROPDOWN
                                           | wx.DP_SHOWCENTURY
                                           | wx.DP_ALLOWNONE )
self.dateEntry.Bind(wx.EVT_DATE_CHANGED, self.OnGetDate)

...

def OnGetDate(self, evt):
    date = evt.GetDate()
    return date
...

def AddEntry(self, evt):
...
cur.execute("insert into entries (ref_no, entry_date, description) values (%s, %s, %s)", (refNo, datetime.date(self.OnGetDate), desc,))

So it says TypeError: an integer is required, I know the problem causing the error is the datetime.date(self.OnGetDate), date has the format datetime.date(yyyy, mm, dd), while the datepickerctrl has (mm/dd/yy). I've tried getting rid of the datetime.date, but another error comes up saying psycopg2.ProgrammingError: can't adapt type 'instancemethod', and I know its saying that because I cant call a method to 开发者_开发问答be inserted to the database. So my question is there another way, to get the date on the widget and place it on the database. I'm having a problem solving either ways. Or am I doing things wrong.


That widget returns a wx.DateTime object, so you'll need to convert it to something that your database understands or maybe the Python datetime object. Here's a thread on how to do the latter: http://wxpython-users.1045709.n5.nabble.com/How-to-convert-wx-DateTime-to-python-datetime-td2352965.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜