title: Tkinter: Why the perimeter of a rectangle grid is not showing?
body: <p>I'm trying to use Tkinter to draw a grid into a rectangle with several rows and columns. I almost have it but, I don't know why, two lines of the perimeter are not showing in the canvas.</p>
  
  <pre class="lang-py prettyprint-override"><code>import tkinter as tk
  
  class GridWindow:
      def __init__(self, parent):
          self.myParent = parent
  
          self.myContainer1 = tk.Frame(parent)
          self.myContainer1.pack()
  
          self.cellwidth = 25
          self.cellheight = 25
          self.rect = {}
  
      def draw_grid(self, rows, columns):
          self.myCanvas = tk.Canvas(self.myContainer1)
          self.myCanvas.configure(width=self.cellheight*rows,
                                  height=self.cellwidth*columns)
          self.myCanvas.pack(side=tk.RIGHT)
  
          for column in range(rows):
              for row in range(columns):
                  x1 = column * self.cellwidth
                  y1 = row * self.cellheight
                  x2 = x1 + self.cellwidth
                  y2 = y1 + self.cellheight
                  self.rect[row, column] = self.myCanvas.create_rectangle(x1, y1, x2, y2, fill="white")
  
  def runApp(rows, columns):
      root = tk.Tk()
      myapp = GridWindow(root)
      myapp.draw_grid(rows, columns)
      root.mainloop()
  
  if __name__ == '__main__':
  runApp(10, 10)
  </code></pre>
  
  <p>With that code the window look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/VfiDG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VfiDG.png" alt="enter image description here"></a></p>
  
  <p>I managed to fix that with a little hack, but I have no idea why it works. The only diference is that now I'm adding 2 pixels to each canvas dimension and 4 to each cell dimension. The code is the following:</p>
  
  <pre class="lang-py prettyprint-override"><code>import tkinter as tk
  
  class GridWindow:
      def __init__(self, parent):
          self.myParent = parent
  
          self.myContainer1 = tk.Frame(parent)
          self.myContainer1.pack()
  
          self.cellwidth = 25
          self.cellheight = 25
          self.rect = {}
  
      def draw_grid(self, rows, columns):
          self.myCanvas = tk.Canvas(self.myContainer1)
          self.myCanvas.configure(width=self.cellheight*rows+2,
                                  height=self.cellwidth*columns+2)
          self.myCanvas.pack(side=tk.RIGHT)
  
          for column in range(rows):
              for row in range(columns):
                  x1 = column * self.cellwidth+4
                  y1 = row * self.cellheight+4
                  x2 = x1 + self.cellwidth
                  y2 = y1 + self.cellheight
                  self.rect[row, column] = self.myCanvas.create_rectangle(x1, y1, x2, y2, fill="white")
  
  def runApp(rows, columns):
      root = tk.Tk()
      myapp = GridWindow(root)
      myapp.draw_grid(rows, columns)
      root.mainloop()
  
  if __name__ == '__main__':
  runApp(10, 10)
  </code></pre>
  
  <p>Now it looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/NimYP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NimYP.png" alt="enter image description here"></a></p>
  
  <p>So I would appreciate if someone could explain me this behaviour or maybe I'm doing something wrong, any suggestion is welcome.</p>