IIPP Week 3 - Canvas, drawing, timers
程序员文章站
2024-03-24 12:08:04
...
Canvas and Drawing
- The origin for canvas is always in the upper left.
- Always drawing while starting
- Just use
draw_test
in draw handler - To draw test
canvas.draw_text(text, point, font_size, font_color)
- To draw circle
canvas.draw_circle(center_point, radius, line_width, line_color)
- To set draw handler
frame.set_draw_handler(draw_handler)
import simplegui
def draw(canvas):
# [100, 100] is the lower left hand portion of the string
canvas.draw_text("Hello!",[100, 100], 24, "White")
canvas.draw_circle([100, 100], 2, 2, "Red")
frame = simplegui.create_frame("Text drawing", 300, 200)
frame.set_draw_handler(draw)
frame.start()
String Processing
slice
### String Processing
# String literals
s1 = "Rixner's funny"
s2 = 'Warren wears nice ties!'
s3 = " t-shirts!"
#print s1, s2
#print s3
# Combining strings
a = ' and '
s4 = "Warren" + a + "Rixner" + ' are nuts!'
print s4
# Characters and slices
print s1[3]
print len(s1)
print s1[0:6] + s2[6:]
print s2[:13] + s1[9:] + s3
# Converting strings
s5 = str(375)
print s5[1:]
i1 = int(s5[1:])
print i1 + 38
'''
Output:
Warren and Rixner are nuts!
n
14
Rixner wears nice ties!
Warren wears funny t-shirts!
75
113
'''
Week 3b - Timers
- To create a timers
simplegui.create_timer(interval, timer_handler)
- Timer and Draw start constantly when program start and never stop?
上一篇: 扫描条形码
下一篇: iText生成 PDF / Word