import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class CalendarWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Calendar Example") self.set_border_width(10) calendar = Gtk.Calendar() self.add(calendar) win = CalendarWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class CalendarWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Calendar Example") self.set_border_width(10) calendar = Gtk.Calendar() calendar.connect("day-selected", self.on_date_selected) self.date_label = Gtk.Label() self.add(calendar) self.add(self.date_label) def on_date_selected(self, calendar): year, month, day = calendar.get_date() self.date_label.set_label("{}/{}/{}".format(month+1, day, year)) win = CalendarWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main()This example creates a window containing a Gtk Calendar widget and a label widget. The label widget is used to display the currently selected date. Whenever the user selects a day on the calendar, the on_date_selected function is called, which updates the label text to display the selected date. The gi.repository package provides Python bindings to the GTK+ 3 library.