import simplegui
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
frame.start()
import simplegui
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
frame.start()
GUI module
initialising an empty frame
start frame
import simplegui
def draw(canvas):
pass
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
frame.set_draw_handler(draw)
frame.start()
draw handler
registering the
draw handler
def button_handler():
button = frame.add_button("Label", button_handler)
def input_handler(text_input):
input = frame.add_input("Label", input_handler, width )
import simplegui
def draw(canvas):
pass
def button_handler():
print "Button pressed"
def input_handler(text_input):
print text_input
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
button = frame.add_button("button", button_handler, 50)
input = frame.add_input("Input", input_handler, 50)
frame.set_draw_handler(draw)
frame.start()
import simplegui
def draw(canvas):
canvas.draw_text("Hey there!", [100,100], 24, "yellow")
canvas.draw_circle([50,50], 10, 5, "red")
def button_handler():
print "Button pressed"
def input_handler(text_input):
print text_input
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
button = simplegui.create_input("button", button_handler)
input = simplegui.create_input("Input", input_handler, 5)
frame.set_draw_handler(draw)
frame.start()
import simplegui
pos = [50,50]
def draw(canvas):
canvas.draw_text("Hey there!", [100,100], 24, "yellow")
canvas.draw_circle(pos, 10, 5, "red")
pos[0] += 2
pos[0] = pos[0] % 300
def button_handler():
print "Button pressed"
def input_handler(text_input):
print text_input
frame = simplegui.create_frame("MyFirstGUI", 300, 200)
button = frame.add_button("button", button_handler, 50)
input = frame.add_input("Input", input_handler, 50)
frame.set_draw_handler(draw)
frame.start()
adding motion
def tick_handler():
timer = simplegui.create_timer(interval, tick_handler)
timer.start()
def keydown():
def keyup():
def mouse_click(mouse_position):
frame.set_keydown_handler(keydown)
frame.set_keyup_hander(keyup)
frame.set_mouseclick_handler(mouse_click)
Define globals
Helper Functions
create a frame
start frame & timer
Classes
register event handlers
Define event handlers