''' from Tkinter import * root = Tk() canvas = Canvas(root, width=300, height=200) canvas.pack() ###Rectangles canvas.create_rectangle(0,0,150,150, fill="yellow") canvas.create_rectangle(100, 50, 250, 100, fill="orange", width=5) canvas.create_rectangle( 50, 100, 150, 200, fill="green", outline="red", width=3) canvas.create_rectangle(125, 25, 175, 190, fill="purple", width=0) ###Ovals, Polygons, Lines, Text #canvas.create_oval(50, 50, 100, 100, fill="yellow") #canvas.create_polygon(50,30,150,50,250,30,150,10, fill="green") canvas.create_line(50, 50, 250, 150, fill="red", width=5) canvas.create_text(150, 100, text="Amazing!", fill="purple", font="Helvetica 26 bold underline") canvas.create_text(150, 100, text="Carpe Diem!", anchor=SW, fill="orange", font="Times 18 italic") root.mainloop() ''' from Tkinter import * root = Tk() canvas = Canvas(root, width=300, height=200) canvas.pack() def drawBelgianFlag(canvas, x0, y0, x1, y1): # draw a Belgian flag in the area bounded by (x0,y0) in # the top-left and (x1,y1) in the bottom-right width = (x1 - x0) canvas.create_rectangle(x0, y0, x0+width/3, y1, fill="black", width=0) canvas.create_rectangle(x0+width/3, y0, x0+width*2/3, y1, fill="yellow", width=0) canvas.create_rectangle(x0+width*2/3, y0, x1, y1, fill="red", width=0) # Draw a large Belgian flag drawBelgianFlag(canvas, 25, 25, 175, 150) # And draw a smaller one below it drawBelgianFlag(canvas, 75, 160, 125, 200) # Now let's have some fun and draw a whole grid of Belgian flags! width = 30 height = 25 margin = 5 for row in range(3): for col in range(3): left = 200 + col * width + margin top = 50 + row * height + margin right = left + width - margin bottom = top + height - margin drawBelgianFlag(canvas, left, top, right, bottom) # Finally, don't forge to display the window! root.mainloop() ''' from Tkinter import * root = Tk() def callback(event): print "clicked at", event.x, event.y frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.pack() root.mainloop() ''' ''' from Tkinter import * root = Tk() def key(event): print "pressed", repr(event.char) def callback(event): frame.focus_set() print "clicked at", event.x, event.y frame = Frame(root, width=100, height=100) frame.bind("", key) frame.bind("", callback) frame.pack() root.mainloop() '''