Chloe Eliza Groth
Chloe Eliza Groth

Reputation: 77

Fill Color Python Graphic (India Flag)

I'm working now on creating the Indian flag in the Graphwin graphics system in python. I'm just missing something with my code right now. When I run this code below, the dark green covers up the white. But when I remove the setFill('darkgreen') from the bottom, the white shows up just fine, and doesn't cover anything else out. What am I missing?

from graphics import *

def main():
  win = GraphWin("India Flag", 500, 500)

  pt = Point(50,50)
  pt.draw(win)

  top = Rectangle(Point(260,100), pt)
  top.setFill('orange')
  top.draw(win)

  pt2 = Point(50, 150)
  middle = Rectangle(Point(260,100), pt2)
  middle.setFill('white')
  middle.draw(win)

  pt3 = Point(50, 200)
  bottom = Rectangle(Point(260,100), pt3)
  bottom.setFill('darkgreen')
  bottom.draw(win)

main ()

any help is appreciated!

Upvotes: 1

Views: 541

Answers (1)

Jose Ricardo Bustos M.
Jose Ricardo Bustos M.

Reputation: 8164

from graphics import *

def main():
  win = GraphWin("India Flag", 500, 500)
  pt = Point(50,50)
  pt.draw(win)
  top = Rectangle(Point(260,100), pt)
  top.setFill('orange')
  top.draw(win)
  pt2 = Point(50, 150)
  middle = Rectangle(Point(260,100), pt2)
  middle.setFill('white')
  middle.draw(win)
  pt3 = Point(260, 200)
  bottom = Rectangle(Point(50,150), pt3)
  bottom.setFill('darkgreen')
  bottom.draw(win)

main()

I get following indian flag:

enter image description here

Upvotes: 2

Related Questions