
Lv.1
签名:QQ:2246454041
在 【Python作品分享】记时器【求助帖】 中回复
from turtle import *
from time import localtime
p = Pen()
screen = Screen()
X = 1000
Y = 600
screen.setup(X, Y)
screen.setworldcoordinates(0, 0, X, Y)
screen.bgcolor("black")
screen.title("记时器")
screen.tracer(0)
p.color('white')
while True:
day = localtime() #获取时间
hour, minute, second = day.tm_hour, day.tm_min, day.tm_sec #挑出时分秒
print(hour, minute, second)
p.write("{}:{}:{}".format(hour, minute, second), font=('Arial', 50, "bold"))
screen.update() #窗口更新
p.clear() #清除画笔痕迹
试试这个
2021-10-03T13:05:27 点赞:0
在 【Python作品分享】计算机【求助帖】 中回复
import random
import turtle
# 电脑
print('欢迎来到计算机')
while True:
a = input('有什么事吗 1=计算 2=游戏 ')
# 计算
if a == '1':
print('好的,正在加载...')
b = eval(input('第一个数是什么? '))
c = eval(input('第二个呢? '))
d = input('什么运算 1=加 2=减 3=乘 4 =除 ')
if d == '1':
print(b + c)
elif d == '2':
print(b - c)
elif d == '3':
print(b * c)
else:
print(b / c)
exit()
# 游戏
if a == '2':
e = input('玩什么游戏?1=猜数 2=图画 3= 画画')
# 猜数
if e == '1':
print('好的,正在加载...')
f = random.randrange(1, 15)
print('我们来玩')
while True:
g = eval(input('数是什么? '))
if g > f:
print('大了')
elif g < f:
print('小了')
else:
print('对了')
h = input('你还想玩吗?1=想 2=不了 ')
if h == '1':
pass
else:
break
# 图画
elif a == '2':
__Pen = turtle.Pen()
def tree(branchLen, t):
if branchLen > 3:
if 8 <= branchLen <= 12:
if random.randint(0, 2) == 0:
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 3))
elif branchLen < 8:
if random.randint(0, 1) == 0:
t.pencolor('snow')
else:
t.pencolor('lightcoral')
t.pensize((branchLen / 2))
else:
t.pencolor('sienna')
t.pensize((branchLen / 10))
t.forward(branchLen)
a = (1.5 * (random.random()))
t.right((20 * a))
b = (1.5 * (random.random()))
tree(branchLen - 10 * b, t)
t.left((40 * a))
tree(branchLen - 10 * b, t)
t.right((20 * a))
t.penup()
t.backward(branchLen)
t.pendown()
# 绘制树下花瓣,参数分别是画板数、画笔
def petal(m, t):
for i in range(m):
a = (200 - 400 * (random.random()))
b = (10 - 20 * (random.random()))
t.penup()
t.forward(b)
t.left(90)
t.forward(a)
t.pendown()
t.pencolor('lightcoral')
t.circle(1)
t.penup()
t.backward(a)
t.right(90)
t.backward(b)
def main():
t = turtle.Pen()
t.hideturtle()
t.speed(0)
turtle.bgcolor('wheat')
t.left(90)
t.penup()
t.backward(150)
t.pendown()
t.pencolor('sienna')
tree(60, t)
petal(100, t)
turtle.done()
main()
2021-10-07T17:23:46 点赞:0