|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 hveagle 于 2022-9-18 14:09 编辑
- eachmonth = [0,31,28,31,30,31,30,31,31,30,31,30,31]
- week = ['下标为0, 占个位', '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
- from tkinter import *
- root = Tk()
- def is366(n):
- if (n % 4 == 0 and n % 100) or n % 400 == 0:
- return True
- else:
- return False
- def whatday(year, month, day):
- num366 = 0
- if year >= 2022:
- if year >= 2024:
- for each in range(2024, year+1, 4):
- if is366(each):
- num366 += 1
- if is366(year) and month < 3:
- num366 -= 1
- deltday = (year - 2022)*365 + sum(eachmonth[:month]) + (day -1) + num366
- return (deltday-1) % 7
- else:
- if year <= 2020:
- for each in range(year, 2022, 4):
- if is366(each):
- num366 += 1
- if is366(year) and month >= 3:
- num366 -= 1
- deltday = (year - 2022)*365 + sum(eachmonth[:month]) + (day -1) - num366
- return (deltday-1) % 7
- class Date:
- def __init__(self, y, m, d):
- self.y = y
- self.m = m
- self.d = d
- self.w = whatday(self.y, self.m, self.d)
- self.row = (self.d + bnum)//7 +2 if (self.d + bnum)%7 else (self.d + bnum)//7 +1
- #以下为主程序
-
- data = []
- y = int(input('请输入年:'))
- m = int(input('请输入月:'))
- em = eachmonth[m]
- bnum = whatday(y, m, 1)
- if m == 2:
- if is366(y):
- em = 29
- for i in range(1, em+1):
- data.append(Date(y, m, i))
- Label(root, text=f'{y}年', fg='blue').grid(row=0, column=2)
- Label(root, text=f'{m}月', fg='blue').grid(row=0, column=4)
- Label(root, text=week[1], fg='red').grid(row=1, column=0)
- Label(root, text=week[2]).grid(row=1, column=1)
- Label(root, text=week[3]).grid(row=1, column=2)
- Label(root, text=week[4]).grid(row=1, column=3)
- Label(root, text=week[5]).grid(row=1, column=4)
- Label(root, text=week[6]).grid(row=1, column=5)
- Label(root, text=week[7], fg='red').grid(row=1, column=6)
- for each in data:
- if each.w == 6 or each.w == 0:
- Label(root, text=str(each.d), fg='red').grid(row=each.row, column=each.w)
- else:
- Label(root, text=str(each.d)).grid(row=each.row, column=each.w)
- mainloop()
复制代码 |
评分
-
查看全部评分
|