def combobox_month_callback(*args): selected_year = int(combobox_year.get()) selected_month = int(combobox_month.get()) days = [] for v in range(1, calendar._monthlen(selected_year, selected_month) + 1): days.append(v) combobox_day.config(values=days) return selected_month
def getTimes(self, start, l): start = self.to_time(start) year = start.year month = start.month monthlen = calendar._monthlen(year, month) for i in range(l): day = (start.day + i) if day > monthlen: day = day - monthlen month += 1 if month > 12: month = month - 12 year += 1 yield datetime(year=year, month=month, day=day)
import calendar print(calendar.weekday(2020, 3, 27))#显示星期几 print(calendar.month(2020, 3))#显示某个月的日历 print(calendar._monthlen(2020, 2))
def combobox_month_callback(*args): selected_year = int(combobox_year.get()) selected_month = int(combobox_month.get()) days = [] for v in range(1, calendar._monthlen(selected_year, selected_month) + 1): days.append(v) combobox_day.config(values=days) return selected_month combobox_month.bind("<<ComboboxSelected>>", combobox_month_callback) combobox_month.place(x=430, y=100) # Day ComboBox days = [] for v in range(1, calendar._monthlen(year, month) + 1): days.append(v) combobox_day = ttk.Combobox(master=root, width=5, state='readonly', values=days) combobox_day.current(day - 1) def combobox_day_callback(*args): return int(combobox_day.get()) combobox_day.bind("<<ComboboxSelected>>", combobox_day_callback) combobox_day.place(x=510, y=100)
%w 星期(0-6),星期天为星期的开始 %W 一年中的星期数(00-53)星期一为星期的开始 %x 本地相应的日期表示 %X 本地相应的时间表示 %Z 当前时区的名称 %% %号本身 ''' #calendar模块 日历 import calendar #w = 每个日期之间的间隔字符数 l = 每周所占用的行数 c = 每个月之间的间隔字符数 print(calendar.calendar(theyear=2020, w=1, l=1, c=4)) #显示全年的日历 print(calendar.month(2020, 1)) #显示某月的日历 print(calendar._monthlen(2020, 2)) #计算某一个月的天数 print(calendar.weekday(2020, 1, 21)) #显示指定日期是星期几 #excel表格操作 读取表格数据 ''' 首先,我们需要导入第三方模块 xlrd ,因为是第三方的模块,没有安装的需要先安装。在命令行中输入: pip install xlrd ''' import xlrd import xlwt import datetime # 打开execl filename = '你好.txt' filename = filename.encode('utf-8') #如果文件名有包含中文,使用编码格式转换
# El usuario introduce su fecha de nacimiento y el programa regresa la edad. # Rocio Pineda import calendar from datetime import date dia_user = int(input("Ingresa el día: ")) mes_user = int(input("Ingresa el mes: ")) anio_user = int(input("Ingresa el anio: ")) dias_mes = calendar._monthlen(anio_user, mes_user) # revisa los dias del mes introducido, falta checar # como poner un excepcion aqui para evitar si el año o mes no es vaido today = date.today() # Obtiene la fecha de hoy edad = today.year - anio_user if dias_mes >= dia_user and edad >= 0: if mes_user < today.month: print("Su edad es: ", edad) if mes_user > today.month: print("Su edad es: ", edad-1) if mes_user == today.month: if dia_user <= today.day: print("Su edad es: ", edad) else: print("Su edad es: ", edad-1) else: print("Escriba una fecha válida")
def update_event(self, inp=-1): self.set_output_val(0, calendar._monthlen(self.input(0), self.input(1)))