HELLO World
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
draw handler
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
Input button
Input field
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()
Drawing on the Canvas
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
More functions
Timers
def tick_handler():
timer = simplegui.create_timer(interval, tick_handler)
timer.start()
Keyboard and Mouse Inputs
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)
Program Structure
Define globals
Helper Functions
create a frame
start frame & timer
Classes
register event handlers
Define event handlers
PingPong
PyStrike
By Namit Juneja
PyStrike
- 476