from graphics import *

def patchdrawer():
    win = GraphWin("Patch drawer", 100, 100)
    for x in range(0, 5):
        for y in range(1, 6):
            p1 = Point(x * 20, (y - 1) * 20)
            p2 = Point((x + 1) * 20, y * 20)
            rectangle = Rectangle(p1, p2)
            if (x + y) % 2 == 0:
                rectangle.setFill("white")
            else:
                rectangle.setFill("red")
            rectangle.draw(win)
    for x in range(0, 10):
        for y in range(0, 10):
            centre = Point(((x + 1) * 10) - 5 , ((y + 1) * 10) - 5)
            circle = Circle(centre, 5)
            if x >= 2 and x < 4 and y >= 0 and y < 2:
                circle.setFill("red")
            elif x >= 6 and x < 8 and y >= 0 and y < 2:
                circle.setFill("red")
            elif x >= 0 and x < 2 and y >= 2 and y < 4:
                circle.setFill("red")
            elif x >= 4 and x < 6 and y >= 2 and y < 4:
                circle.setFill("red")
            elif x >= 8 and x < 10 and y >= 2 and y < 4:
                circle.setFill("red")
            elif x >= 2 and x < 4 and y >= 4 and y < 6:
                circle.setFill("red")
            elif x >= 6 and x < 8 and y >= 4 and y < 6:
                circle.setFill("red")
            elif x >= 0 and x < 2 and y >= 6 and y < 8:
                circle.setFill("red")
            elif x >= 4 and x < 6 and y >= 6 and y < 8:
                circle.setFill("red")
            elif x >= 8 and x < 10 and y >= 6 and y < 8:
                circle.setFill("red")
            elif x >= 2 and x < 4 and y >= 8 and y < 10:
                circle.setFill("red")
            elif x >= 6 and x < 8 and y >= 8 and y < 10:
                circle.setFill("red")
            else:
                circle.setFill("white")
            circle.draw(win)
    win.getMouse()
    win.close()
    win.getMouse()
    win.close() 

You can shorten the tests

from graphics import *

def patchdrawer():
    win = GraphWin("Patch drawer", 100, 100)
    for x in range(0, 5):
        for y in range(1, 6):
            p1 = Point(x * 20, (y - 1) * 20)
            p2 = Point((x + 1) * 20, y * 20)
            rectangle = Rectangle(p1, p2)
            rectangle.setFill("red" if (x + y) % 2 else "white")
            rectangle.draw(win)
    for x in range(0, 10):
        for y in range(0, 10):
            centre = Point(((x + 1) * 10) - 5 , ((y + 1) * 10) - 5)
            circle = Circle(centre, 5)
            circle.setFill("white" if (x % 4) // 2 == (y % 4) // 2 else "red")
            circle.draw(win)
    win.getMouse()
    win.close()

if __name__ ==  "__main__":
    patchdrawer()

Thank you very much, new programming and python

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.