Gtk.Calendar
日历部件
继承关系
Methods
| 方法修饰词 | 方法名及参数 |
|---|---|
| static | new () |
| clear_marks () | |
| get_date () | |
| get_day_is_marked (day) | |
| get_detail_height_rows () | |
| get_detail_width_chars () | |
| get_display_options () | |
| mark_day (day) | |
| select_day (day) | |
| select_month (month, year) | |
| set_detail_func (func, *data) | |
| set_detail_height_rows (rows) | |
| set_detail_width_chars (chars) | |
| set_display_options (flags) | |
| unmark_day (day) |
Virtual Methods
| do_day_selected () |
| do_day_selected_double_click () |
| do_month_changed () |
| do_next_month () |
| do_next_year () |
| do_prev_month () |
| do_prev_year () |
Properties
| Name | Type | Flags | Short Description |
|---|---|---|---|
| day | int | r/w/en | The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day) |
| detail-height-rows | int | r/w/en | Details height in rows |
| detail-width-chars | int | r/w/en | Details width in characters |
| month | int | r/w/en | The selected month (as a number between 0 and 11) |
| no-month-change | bool | r/w/en | If True, the selected month cannot be changed |
| show-day-names | bool | r/w/en | If True, day names are displayed |
| show-details | bool | r/w/en | If True, details are shown |
| show-heading | bool | r/w/en | If True, a heading is displayed |
| show-week-numbers | bool | r/w/en | If True, week numbers are displayed |
| year | int | r/w/en | The selected year |
Signals
| Name | Short Description |
|---|---|
| day-selected | Emitted when the user selects a day. |
| day-selected-double-click | Emitted when the user double-clicks a day. |
| month-changed | Emitted when the user clicks a button to change the selected month on a calendar. |
| next-month | Emitted when the user switched to the next month. |
| next-year | Emitted when user switched to the next year. |
| prev-month | Emitted when the user switched to the previous month. |
| prev-year | Emitted when user switched to the previous year. |
例子
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/28
# section 107
TITLE = "Calendar"
DESCRIPTION = """
Gtk.Calendar is a widget that displays a Gregorian calendar, one month at a time
"""
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 Demo")
self.set_border_width(10)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
cal = Gtk.Calendar()
self.today = cal.get_date()
print(self.today)
# 每个月的这一天都有标记,不合理啊
# cal.mark_day(1)
# show details
cal.props.show_details = True
# create detail
cal.set_detail_func(self.detail, "haha")
cal.connect("day-selected", self.day_selected)
cal.connect("day-selected-double-click", self.day_selected_double_click)
cal.connect("month-changed", self.month_changed)
cal.connect("next-month", self.next_month)
# other signals
# next-year
# prev-month
# prev-year
box.add(cal)
self.label = Gtk.Label()
box.add(self.label)
self.add(box)
def day_selected(self, cal):
print("day_selected", cal.props.day)
self.label.set_label("day_selected:%d" % cal.props.day)
def day_selected_double_click(self, cal):
print("day_selected_double_click", cal.props.day)
self.label.set_label("day_selected_double_click:%d" % cal.props.day)
def month_changed(self, cal):
print("month_changed", cal.props.month + 1)
self.label.set_label("month_changed:%d" % (cal.props.month + 1))
def next_month(self, cal):
print("next_month", cal.props.month + 1)
self.label.set_label("next_month:%d" % (cal.props.month + 1))
def detail(self, cal, y, m, d, value):
# print(y, m, d)
if y == self.today[0] and m == self.today[1] and d == self.today[2]:
# 设置详细信息高度和宽度
cal.set_detail_height_rows(2)
cal.set_detail_width_chars(5)
return "<b>today</b>"
def main():
win = CalendarWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728

本文介绍Gtk.Calendar组件的使用方法,包括其属性、信号和方法。通过一个Python示例展示了如何创建日历,设置细节显示,并连接各种事件处理函数。
67

被折叠的 条评论
为什么被折叠?



