python海龟画图制作的温度计模拟交互动画

python温度模拟器动画制作

"""本程序实现一个温度计模拟,需要thermometer支持,模块在下面
from thermometer import * 

"""自定义形坐标点,不采用内置的square的原因是它以中心点为旋转中心,
   页这个是以最下边中心点为旋转中心,所以伸长的时候不会向两边伸长。"""

width,height  = 300,840

screen = Screen()                     # 新建屏幕对象
screen.colormode(255)                 # 颜色模式为RGB255
screen.setup(width,height)            # 设定屏幕的宽和高
screen.delay(0)                       # 设定绘画延时
screen.addshape("mysquare",p)         # 注册 mysquare 形状
screen.addshape("ball-red.gif")       # 注册gif图
screen.addshape("ball-cyan.gif")
screen.addshape("sun.gif")
screen.addshape("snow.gif")
screen.addshape("button1+.gif")
screen.addshape("button1-.gif")

screen.bgpic("背景短空.png")

"新建温度计对象,参数为初始温度"
temperature = 60
therm = Thermometer(temperature)      # 接受整型参数,-28到80之间
therm.shape("mysquare")               # 设定形状为mysquare

button_add = Button("button1+.gif",100,-350,therm,"+")
button_sub = Button("button1-.gif",-100,-350,therm,"-")

screen.onkeypress(therm.lengthen,"plus")# 绑定+号按键到wdj.lengthen (加长)函数按键表:https://www.tcl.tk/man/tcl8.4/TkCmd/keysyms.htm
screen.onkeypress(therm.shorten,"minus")# 绑定-号按键到wdj.shorten  (变短)函数

screen.listen()                       # 设置焦点,监听键盘
screen.mainloop()                     # 刷新组件,进入主循环

You must log in to read the rest of this article. Please log in or register as a user.