获取中...

-

Just a minute...

python课老师让做万年历,之前用C写过,这次用python写个带视窗的,哈哈哈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import tkinter
import tkinter.messagebox

def runnian(year):
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
return True
else:
return False

def yue(year, month):
days = 31
if month == 2:
if runnian(year):
days = 29
else:
days = 28
elif month == 4 or month == 6 or month == 9 or month == 11:
days = 30
return days

def totaldays(year, month):
days = 0
for i in range(1, year):
if runnian(i):
days += 366
else:
days += 365
for i in range(1, month):
days += yue(year, i)
return days

def f():
year = n1.get()
month = y1.get()
year = int(year)
month = int(month)
if not 1 <= month <= 12:
tkinter.messagebox.showerror(title='出错了', message='输入1~12啊')
count = 0
day = []
day.append("日\t一\t二\t三\t四\t五\t六\n")
for i in range((totaldays(year, month) % 7) + 1):
day.append('\t')
count += 1
if count == 7:
day.append('\n')
for i in range(1, yue(year, month) + 1):
day.append(str(i))
count += 1
if count % 7 == 0:
day.append('\n')
else:
day.append('\t')
if count % 7 != 0:
for i in range(7 - count % 7 - 1):
day.append('\t')
day.append(' ')
w.config(text="".join(day))



window = tkinter.Tk()
window.title('小茗同学制作的万年历')
window.minsize(600,350)
window.maxsize(600,350)



n = tkinter.Label(window, text="请输入想要查询的年份:",bg='yellow',font=('Arial', 10))
n.pack()

n1 = tkinter.StringVar()
entry_year= tkinter.Entry(window, textvariable=n1).pack()

y = tkinter.Label(window, text="请输入想要查询的月份:",bg='yellow',font=('Arial', 10))
y.pack()

y1 = tkinter.StringVar()
entry_mon = tkinter.Entry(window, textvariable=y1).pack()

b = tkinter.Button(text='查看万年历',command=f,bg='yellow')
b.pack()


w = tkinter.Label(window, text="")
w.pack()


window.mainloop()

贴一张图,嘻嘻

相关文章
评论
分享
  • 贪吃蛇

    贪吃蛇 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606...

    贪吃蛇
  • 网鼎杯部分wp

    pwnboom1分析远程已经打不通了,远程的偏移和本地的偏移不一样,只能复现一下本地的了。 首先看到流程图,代码量很大,有很大的switch语句和嵌套结构,可能是虚拟机或者是解析器。 从下图看出是一个C语言的解析器。 然后看了...

    网鼎杯部分wp
  • 网络设备配置与管理

    Linux网络设备与管理大作业 下图为某企业网络拓扑图,接入层采用二层交换机2960,汇聚和核心层使用了一台三层交换机3560 24PS,局域网边缘采用一台路由器LanRouter用于连接到外部网络的Isp Router两台路由器...

    网络设备配置与管理
Please check the parameter of comment in config.yml of hexo-theme-Annie!