学了点函数调用
customer.py
| |
| |
| from turtle import * |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| def square(x, y, l): |
| penup() |
| goto(x, y) |
| pendown() |
| setheading(0) |
| i = 0 |
| while i < 4: |
| forward(l) |
| right(90) |
| i = i + 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| def rect(x, y, w, h): |
| penup() |
| goto(x,y) |
| pendown() |
| setheading(0) |
| i = 0 |
| while i < 2: |
| forward(w) |
| right(90) |
| forward(h) |
| right(90) |
| i = i + 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| def square5(): |
| i = 0 |
| x = 0 |
| while i < 5: |
| square(x,0,30) |
| x = x + 30 |
| i = i + 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| def square5_10(): |
| i = 0 |
| x = 0 |
| while i < 5: |
| square(x,0,30) |
| x = x + 40 |
| i = i + 1 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| def square_line(x,y,n,space,length): |
| i = 0 |
| while i < n: |
| square(x,y,length) |
| x = x + length + space |
| i = i + 1 |
main.py
| |
| |
| |
| |
| |
| |
| from turtle import * |
| from customer import action |
| |
| |
| def clean_screen(): |
| clear() |
| penup() |
| home() |
| pendown() |
| showturtle() |
| |
| |
| def close(): |
| bye() |
| |
| |
| def main(): |
| setup(width=800, height=600, startx=0, starty=0) |
| title('按 S 开始绘图,按 D 清除界面,按 Esc 关闭') |
| showturtle() |
| speed(2) |
| onkeyrelease(action, 's') |
| onkeyrelease(clean_screen, 'd') |
| onkeyrelease(close, 'Escape') |
| listen() |
| done() |
| |
| |
| if __name__ == '__main__': |
| main() |
学习了基本的定义函数和相关调用知识,比如:
| > if __name__ == '__main__': |
| main() |
明天见!
Comments NOTHING