当前位置:文档之家› 时间打印

时间打印

import turtle, time

def drawGap(): # 绘制数码管间隔
turtle.penup()
turtle.fd(5)

def drawLine(draw): #绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
drawGap()
turtle.right(90)

def drawDigit(d): #根据数字绘制七段数码管
drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False)
drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,2,6,8] else drawLine(False)
turtle.left(90)
drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False)
drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False)
turtle.left(180)
turtle.penup()
turtle.fd(20)

def drawDate(date):
turtle.pencolor("red")
for i in date:
if i == '-':
turtle.write('年',font=("Arial", 18, "normal"))
turtle.pencolor("orange")
turtle.fd(40)
elif i == '^':
turtle.write('月',font=("Arial", 18, "normal"))
turtle.pencolor("green")
turtle.fd(40)
elif i == '+':
turtle.write('日',font=("Arial", 18, "normal"))
turtle.pencolor("cyan")
turtle.fd(40)
elif i == '*':
turtle.write('时',font=("Arial", 18, "normal"))
turtle.pencolor("blue")
turtle.fd(40)
elif i == '/':
turtle.write('分',font=("Arial", 18, "normal"))
turtle.pencolor("purple")
turtle.fd(40)
elif i == '@':
turtle.write('秒',font=("Arial", 18, "normal"))
else:
drawDigit(eval(i))

def zidingyi(Y,m,d,H,M,S):
def main():
turtle.setup(width=1.0, height=1.0, startx=0, starty=0)
turtle.penup()
turtle.fd(-600)
turtle.pensize(5)
drawDate(('{}-{}^{}+{}*{}/{}@').format(Y,m,d,H,M,S))
turtle.hideturtle()
turtle.done()
main()

def xitong():
def main():
turtle.setup(width=1.0, height=1.0, startx=0, starty=0)
turtle.penup()
turtle.fd(-600)
turtle.pensize(5)
drawDate(time.strftime('%Y-%m^%d+%H*%M/%S@',time.localtime()))
turtle.hideturtle()
turtle.done()
main()

import tkinter as tk
root=https://www.doczj.com/doc/0713553945.html,()
root.geometry("600x400+500+200")
def new():
top=tk.Toplevel()
top.title('自定义时间')
top.geometry("600x400+500+200")
L1 = https://www.doczj.com/doc/0713553945.html,bel(top, text="年")
L1.place(relx=0.06, rely=0.2)
E1 = tk.Entry(top, bd=5)
E1.place(relx=0.09, rely=0.2)

L2 = https://www.doczj.com/doc/0713553945.html,bel(top, text="月")
L2.place(relx=0.36, rely=0.2)

E2 = tk.Entry(top, bd=5)
E2.place(relx=0.39, rely=0.2)

L3 = https://www.doczj.com/doc/0713553945.html,bel(top, text="日")
L3.place(relx=0.66, rely=0.2)
E3 = tk.Entry(top, bd=5)
E3.place(relx=0.69, rely=0.2)

L4 = https://www.doczj.com/doc/0713553945.html,bel(top, text="时")
L4.place(relx=0.06, rely=0.4)
E4 = tk.Entry(top, bd=5)
E4.place(relx=0.09, rely=0.4)

L5 = https://www.doczj.com/doc/0713553945.html,bel(top, text="分")
L5.place(relx=0.36, rely=0.4)
E5 = tk.Entry(top, bd=5)
E5.place(relx=0.39, rely=0.4)

L6 = https://www.doczj.com/doc/0713553945.html,bel(top, text="秒")
L6.place(relx=0.66, rely=0.4)
E6 = tk.Entry(top, bd=5)
E6.place(relx=0.69, rely=0.4)

def Z():
Y = E1.get()
m = E2.get()
d = E3.get()
H = E4.get()
M = E5.get()
S = E6.get()
zidingyi(Y,m,d,H,M,S)

qr=tk.Button(top,text='确认',command=Z)
qr.configure(width=15, height=2)
qr.place(relx=0.2, rely=0.7)
fh=tk.Button(top,text='关闭',command=top.quit)
fh.configure(width=15, height=2)
fh.place(relx=0.6, rely=0.7)

zd=tk.Button(root,text='自定义时间',font='Helvetica -30 bold',command=new)
zd.configure(width=30, height=3)
zd.place(relx=0.5, rely=0.65, anchor='center')

xt=tk.Button(root,text='系统时间',font='Helvetica -30 bold',command=xitong)
xt.configure(width=30, height=3)
xt.place(relx=0.5, rely=0.35, anchor='center')

tk.mainloop()

相关主题
文本预览
相关文档 最新文档