Week 5a - Mouse Input and More Lists
Mouse Input
def click_handler(pos)
frame.set_mouseclick_handler(click_handler)
List Methods
- in
- index
- append
- pop,
remove("a") != pop(list.index("a"))
前者不返回值,后者返回值
Iteration
Tips: We cannot change the value when iterating
for
can be used to change the value or screen value
return x ** 2 for x in range(0, 5)
[return x ** 2 for x in range(0, 5)]
return x for x in range(0, 10) if x % 2 == 0
Week 5b - Dictionaries and Images
Dictionary
dic = {}
is same as dic = dict()
Key
We just can use hashable type like tuples, booleans, numbers, strings , class as the key of dictionary
But what is hashable?
The value can be any type
Iterate
- for key in dic
- for value in dic.value()
- for key, value in dic.item()
Image
canvas.draw_image(image, center_source, width_height_source, center_dest, width_height_dest)
- draw_image()
- simplegui.load_image
- get.width()
- get.height()
Change Label
label1 = frame.add_label("haha")
label1.set_text("hehe")