well basically i have to draw a stick figure for which is my first question... i cant figure out how to draw a horizontal line and also a line at a angle for the legs... here is the code for the first one

def drawStickFigure():
from graphics import *
win = GraphWin("Stick figure")
head = Circle(Point(100, 60), 20)
head.draw(win)
body = Line(Point(100, 80), Point(100, 120))
body.draw(win)
arms= Line(Point(0, 100), Point(0, 100))
arms.draw(win)

for the second question i have to draw a circle which is at the centre of the graphics window. the user inputs the radius of the circle and the circle should come. But for some reasn my code doesnt seem to be working please help

def drawCircle():
x = input("please enter the radius of the circle: ")
centre= Point(100, 100)
circle1 = Circle(centre, x)
circle1.draw(win)

I hope you are not stuck with an outdated module like graphics, which is a wrapper for Tkinter, written by some guy to sell his book. You are much better off using the Tkinter GUI toolkit directly and learn something you can actually use later on.

To say it bluntly, the module graphics is all candy and no meat!

Edited 7 Years Ago by vegaseat: candy

And it's not tough to do.

import Tkinter

root = Tkinter.Tk()
root.title('Canvas')
canvas = Tkinter.Canvas(root, width=450, height=450)

canvas.create_oval(100,50,150,100, fill='gray90')

x = 125
y = 175
stick = canvas.create_line(x, y-75, x, y)

diff_x = 25
stick_leg1 = canvas.create_line(x, y, x-diff_x, y+50)
stick_leg2 = canvas.create_line(x, y, x+diff_x, y+50)

y=145
stick_arm1 = canvas.create_line(x, y, x-30, y-20)
stick_leg2 = canvas.create_line(x, y, x+30, y-10)

canvas.pack()
root.mainloop()

But for some reasn (reason) my code doesnt (doesn't) seem to be working

What version of Python are you using? Make sure you are using an integer for the radius.

def draw_circle():
    x = input("please enter the radius of the circle: ")
    print "the radius is", x, type(x)
    centre= Point(100, 100)
    circle1 = Circle(centre, x)
    circle1.draw(win)

Edited 7 Years Ago by woooee: n/a

He is using the graphics file from a python book. Your code for the stick figure would look like this. The Line command uses two points(x,y) for the starting point and (x,y) for the ending point.

def drawStickFigure():
    from graphics import *
    win = GraphWin("Stick figure")
    head = Circle(Point(100, 60), 20).draw(win)
    body = Line(Point(100, 80), Point(100, 120)).draw(win)
    arms= Line(Point(60, 100), Point(140, 100)).draw(win)
    leg1 = Line(Point(100,120), Point(60,160)).draw(win)
    leg2 = Line(Point(100,120), Point(140,160)).draw(win)    
drawStickFigure()

For the circle you need to use setCoords to make sure that it is in the center of the window.

from graphics import *
def drawCircle():
    win = GraphWin("Stick figure",500,500)
    win.setCoords(-20,-20,20,20)#By setting the coords to this the center is at (0,0)
    x = input("please enter the radius of the circle: ")
    center = Point(0,0)
    circle1 = Circle(center, x)
    circle1.draw(win)
drawCircle()

Hi, I have started a stick figure class with all of the parts as the legs and arms but, I now need to make the arms either rotate or wave and make one eye wink also how to make that code function constantly with stopping. I could use some example codes or advice on how to complete this task.

Sounds like a fun project.

My advice, do not hijack old solved threads, but start your own new thread, it's more polite and people are more willing to help. Give your new thread a meaningful title like "Making a stick figure class".

Give us a hint what OS and Python version you are using. Also the type of GUI toolkit you have decided on. I recommend Tkinter for beginners, it comes with Python.

Edited 3 Years Ago by bumsfeld

This question has already been answered. Start a new discussion instead.