3

I want to draw a Grid World (similar to a table), where cells may contain robots or obstacles. A dot/arrow would do to represent the robot and colouring the cells in black for examples could represent the obstacles.

I am not looking for anything complicated, just a simple python library that would help me do this. Any suggestions?

Karan
  • 14,824
  • 24
  • 91
  • 157

1 Answers1

1

tkinter has a canvas widget that is pretty easy to work with. It has primitives for lines and filled polygons and circles and so on. And with the event loop its pretty easy to do simple animations.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • i was looking at tkinter. I used a grid to align labels. However, they are currently borderless and are of different sizes. Do you know how to add the borders and make every cell uniform (so it looks more like a grid?) – Karan Jan 26 '11 at 21:12
  • 1
    @Newton: give the labels a borderwidth of 1 and a relief of "solid". Or, be clever and give each cell a tiny bit of padding and give the containing frame a different color so that it peeks through. If you're using the grid geometry manager be sure to give each cell the `sticky` attribute a value of "nsew" so the label expands to fill the entire cell. – Bryan Oakley Jan 26 '11 at 22:27
  • Thanks for your help, it did the job. I was wondering if you knew how to draw arrows inside the cells. I could probably paste an image on top of the label, but I would prefer if I could control the width of the arrow dynamically (for example, the arrow gets bolder as you click a button). I havent used a canvas so far since I havent needed it ... simply arranged labels in a grid position. I am guessing I would need to use a canvas for this. If that is the case, would I have to integrate the labels in the canvas? – Karan Jan 28 '11 at 12:52
  • @Newton: the only way to draw in Tk is with the Canvas object. This lets you embed widgets, but the widgets will always be above the drawing. So, to accomplish what you want requires that the whole thing be done on a canvas. – Bryan Oakley Jan 28 '11 at 21:26