hi, i want to be able to draw two eyes with are exactly the same in radius and colour etc next to eachother. So when i open the window the pair of eyes are there in the centre. I have managed to get one eye but i dnt have a clue to how to get one beside it, i am not sure hw to.. here is my code for the first eye and function should be calling the drawCircle six times.
please help

from graphics import *
import math
def drawCircle(win, centre, radius, colour):
circle = Circle(centre, radius)
circle.setFill(colour)
circle.setWidth(2)
circle.draw(win)

def drawTarget():
win = GraphWin()
centre = Point(100,100)
drawCircle(win, centre, 40, "white")
drawCircle(win, centre, 20, "blue")
drawCircle(win, centre, 10, "black")

Recommended Answers

All 6 Replies

One eye has to be positioned center_left, the other center_right ...

from graphics import *
import math

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawTarget():
    win = GraphWin()
    centre_left = Point(50,100)
    centre_right = Point(150,100)
    drawCircle(win, centre_left, 40, "white")
    drawCircle(win, centre_left, 20, "blue")
    drawCircle(win, centre_left, 10, "black")
    drawCircle(win, centre_right, 40, "white")
    drawCircle(win, centre_right, 20, "blue")
    drawCircle(win, centre_right, 10, "black")    
    # this keeps the window up/open
    win.getMouse()

drawTarget()

For those who don't know ...

John Zelle, Ph.D. teaches Python at Wartburg College
he is the author of graphics.py used by a number of schools instead
of Tkinter

Here is the graphics module (a thin wrapper for Tkinter) ...
http://mcsp.wartburg.edu/zelle/python/graphics.py
also has a nice documentation ...
http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

http://mcsp.wartburg.edu/zelle

Founded in 1852, Wartburg College is a nationally recognized selective
four-year liberal arts college of the Evangelical Lutheran Church in
America.

Wartburg College
100 Wartburg Blvd.
Waverly, IA 50677
(800) 772-2085

"Be Orange"

At this point in time module graphics.py works with Python2 only.
Install graphics.py in your working directory or the Lib/site-packages directory.

but hw would you get them in the exact centre of the graphics window.. is this fine?

from graphics import *
import math

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawTarget():
    win = GraphWin()
    centre_left = Point(60,100)
    centre_right = Point(140,100)
    drawCircle(win, centre_left, 40, "white")
    drawCircle(win, centre_left, 20, "blue")
    drawCircle(win, centre_left, 10, "black")
    drawCircle(win, centre_right, 40, "white")
    drawCircle(win, centre_right, 20, "blue")
    drawCircle(win, centre_right, 10, "black")    
    # this keeps the window up/open
    win.getMouse()

drawTarget()

One way would be to say that the center should be at 1/2 width and height of the drawing window ...

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawTarget():
    w = 250
    h = 250
    win = GraphWin("Spooky Eyes", w, h)
    # center should be at 1/2 width and height
    center_w = w//2
    center_h = h//2
    centre_left = Point(center_w - 50, center_h)
    centre_right = Point(center_w + 50, center_h)
    drawCircle(win, centre_left, 40, "white")
    drawCircle(win, centre_left, 20, "blue")
    drawCircle(win, centre_left, 10, "black")
    drawCircle(win, centre_right, 40, "white")
    drawCircle(win, centre_right, 20, "blue")
    drawCircle(win, centre_right, 10, "black")    
    # this keeps the window up/open
    win.getMouse()

drawTarget()

thankyou.. that makes sense nw.. had to tweak code a bit more for my requirements.. thx a lot..

can i quickly just ask a question, would we be able to shrink the code anymore if it was just for one eye?.. as it has repetitive code?

One eye would make it simpler ...

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawTarget():
    w = 250
    h = 250
    win = GraphWin("One Spooky Eye", w, h)
    # center should be at 1/2 width and height
    centre = Point(w//2, h//2)
    drawCircle(win, centre, 40, "white")
    drawCircle(win, centre, 20, "blue")
    drawCircle(win, centre, 10, "black")
    # click mouse to go on
    win.getMouse() 
    win.close()

drawTarget()

You can streamline the whole thing a little more using a for loop ...

# draw one spooky eye in the center of the drawing window
# calculate the center from width, height

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawTarget():
    w = h = 250
    win = GraphWin("One Spooky Eye", w, h)
    # center should be at 1/2 width and height
    centre = Point(w//2, h//2)
    for radius, color in ((40,"white"), (20,"blue"), (10,"black")):
        drawCircle(win, centre, radius, color)
    # click mouse to go on
    win.getMouse() 
    win.close()

drawTarget()

Stop before the code gets too cryptic and hard to read and understand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.