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:

image grid

you same drawing whole lines (as described in docs) if necessary, @ cost of drawing speed (depending on how big grid size should be).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -