Calvin (Deutschbein)
W7Wed: 09 Oct
GRect(x,y,w,h) ;
|
|
def my_rect(x,y,w,h,color):
rect = GRect(x,y,w,h)
rect.set_filled(True)
rect.set_color(color)
gw.add(rect)
add_event_listener(type, fn)
- Registers a new listener for events of the specified type occuring in the window. The type parameter should be one of the strings "mousedown", "mouseup", "click", "mousemove", "mousemove", or "drag".
Usage: timer = gw.add_event_listener(type, fn) Parameter:
type The event type fn The callback function
from pgl import *
def click_func(e): # 'e' is a "MouseEvent"
print(e) # let's look at 'e'
gw = GWindow(400,400)
gw.add_event_listener("click",click_func)
<pgl.GMouseEvent object at 0x000001FA27BDCBC0>
from pgl import *
def click_func(e): # 'e' is a "MouseEvent"
print('x = ', e.get_x())
print('y = ', e.get_y())
gw = GWindow(400,400)
gw.add_event_listener("click",click_func)
x = 143
y = 148
|
|
|
|
gw.box.set_location(x,y)
from pgl import *
# same click func
def click_func(e):
x = e.get_x()
y = e.get_y()
gw.box.set_location(x,y)
gw = GWindow(400,400)
# same as my rect, but on "gw.box"
gw.box = GRect(400,400,50,50)
gw.box.set_filled(True)
gw.box.set_color('pink')
gw.add(gw.box)
gw.add_event_listener("click",click_func)
|
|