鱼C论坛

 找回密码
 立即注册
查看: 4489|回复: 1

[作品展示] 1 月历

[复制链接]
发表于 2022-8-5 09:24:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 hveagle 于 2022-9-18 14:09 编辑
  1. eachmonth = [0,31,28,31,30,31,30,31,31,30,31,30,31]
  2. week = ['下标为0, 占个位', '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']

  3. from tkinter import *
  4. root = Tk()



  5. def is366(n):
  6.     if (n % 4 == 0 and n % 100) or  n % 400 == 0:
  7.         return True
  8.     else:
  9.         return False

  10. def whatday(year, month, day):
  11.     num366 = 0
  12.     if year >= 2022:
  13.         if year >= 2024:
  14.             for each in range(2024, year+1, 4):
  15.                 if is366(each):
  16.                     num366 += 1
  17.             if is366(year) and month < 3:
  18.                 num366 -= 1
  19.         deltday = (year - 2022)*365 + sum(eachmonth[:month]) + (day -1) + num366
  20.         return (deltday-1) % 7
  21.     else:
  22.         if year <= 2020:
  23.             for each in range(year, 2022, 4):
  24.                 if is366(each):
  25.                     num366 += 1
  26.             if is366(year) and month >= 3:
  27.                 num366 -= 1
  28.         deltday = (year - 2022)*365 + sum(eachmonth[:month]) + (day -1) - num366
  29.         return (deltday-1) % 7


  30. class Date:
  31.     def __init__(self, y, m, d):
  32.         self.y = y
  33.         self.m = m
  34.         self.d = d
  35.         self.w = whatday(self.y, self.m, self.d)
  36.         self.row = (self.d + bnum)//7 +2 if (self.d + bnum)%7 else (self.d + bnum)//7 +1

  37. #以下为主程序
  38.         
  39. data = []
  40. y = int(input('请输入年:'))
  41. m = int(input('请输入月:'))
  42. em = eachmonth[m]
  43. bnum = whatday(y, m, 1)
  44. if m == 2:
  45.     if is366(y):
  46.         em = 29

  47. for i in range(1, em+1):
  48.     data.append(Date(y, m, i))

  49. Label(root, text=f'{y}年', fg='blue').grid(row=0, column=2)
  50. Label(root, text=f'{m}月', fg='blue').grid(row=0, column=4)
  51. Label(root, text=week[1], fg='red').grid(row=1, column=0)
  52. Label(root, text=week[2]).grid(row=1, column=1)
  53. Label(root, text=week[3]).grid(row=1, column=2)
  54. Label(root, text=week[4]).grid(row=1, column=3)
  55. Label(root, text=week[5]).grid(row=1, column=4)
  56. Label(root, text=week[6]).grid(row=1, column=5)
  57. Label(root, text=week[7], fg='red').grid(row=1, column=6)

  58. for each in data:
  59.     if each.w == 6 or each.w == 0:
  60.         Label(root, text=str(each.d), fg='red').grid(row=each.row, column=each.w)
  61.     else:
  62.         Label(root, text=str(each.d)).grid(row=each.row, column=each.w)

  63. mainloop()
复制代码

评分

参与人数 4荣誉 +3 鱼币 +12 贡献 +6 收起 理由
Jason茗 + 1 鱼C有你更精彩^_^
okkboss + 5 无条件支持楼主!
柿子饼同学 + 3 + 3
青出于蓝 + 3 + 3 + 3 无条件支持楼主!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-9-22 17:29:48 | 显示全部楼层
啊这
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 17:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表