Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected date from python wx.lib.calendar

How do you make button which open calendar then selects date and closes it? So far I managed just create calendars (I don't get why it always creates 2). But I couldn't figure out how to get selected date. I'm using pythonwx on Python 3.

class MyCalendar(wx.Frame):

    def __init__(self, *args, **kargs):
        wx.Frame.__init__(self, *args, **kargs)
        self.cal = CalendarCtrl(self, 10, wx.DateTime.Now())
        self.timer = wx.Timer(self)



if __name__ == '__main__':  
    app = wx.App()
    frame = MyCalendar(None)
    frame.Show()
    app.MainLoop()

EDIT

adding py3 version

from wx.adv import CalendarCtrl, GenericCalendarCtrl, CalendarDateAttr

class MyCalendar(wx.Frame):

    def __init__(self, *args, **kargs):
        wx.Frame.__init__(self, *args, **kargs)
        self.cal = CalendarCtrl(self, 10, wx.DateTime.Now())
        self.cal.Bind(wx.adv.EVT_CALENDAR, self.OnDate)



    def OnDate(self,event):
        print (self.cal.GetDate())      
        wx.Window.Close(self)
like image 689
Nastyjoe Avatar asked Jun 12 '26 15:06

Nastyjoe


1 Answers

import wx
import wx.adv
class MyCalendar(wx.Frame):

    def __init__(self, *args, **kargs):
        wx.Frame.__init__(self, *args, **kargs)
        self.cal = wx.adv.CalendarCtrl(self, 10, wx.DateTime.Now())
        self.cal.Bind(wx.adv.EVT_CALENDAR, self.OnDate)

    def OnDate(self,event):
        print(self.cal.GetDate())


if __name__ == '__main__':
    app = wx.App()
    frame = MyCalendar(None)
    frame.Show()
    app.MainLoop()

Now double click on a date.

I'll leave you to research creating a frame/panel and putting a button on it, to activate the calendar.

like image 113
Rolf of Saxony Avatar answered Jun 14 '26 03:06

Rolf of Saxony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!