How to draw grid on window using graphics library in python -
i want draw grid onto window can draw rectangles , know exact points. have not been able figure out way in python using graphics library. there better method?
i not find online uses graphics mostly.
this have far:
from graphics import * def main(): win = graphwin('floor', 500, 500) win.setcoords(0.0, 0.0, 10.0, 10.0) win.setbackground("yellow") square = rectangle(point(5,5), point(6,6)) square.draw(win) square.setfill("black") win.getmouse() win.close() main()
an easy way add grid calculating pixels yourself:
from graphics import * def main(): win = graphwin('floor', 500, 500) win.setcoords(0.0, 0.0, 10.0, 10.0) win.setbackground("yellow") # draw grid x in range(10): y in range(10): win.plotpixel(x*50, y*50, "blue") square = rectangle(point(5,5), point(6,6)) square.draw(win) square.setfill("black") win.getmouse() win.close() main()
which adds 10x10 pixel grid yellow window:
you same drawing whole lines (as described in docs) if necessary, @ cost of drawing speed (depending on how big grid size should be).
Comments
Post a Comment