title: Automatically resize text widget's width to fit all text
body: <p>I am attempting to print out tables using the Text widget. I have created a method for doing this by using labels and frames, but the problem is that I will need to present larger tables to the point where I will need to use a scroll bar.</p>
  <p>I am using tabs to make a table for the text widget, and it works well, but I can't seem to figure out a way to set the width of the widget to fit the text. I'm attempting to do it with the get_width() method below, but it doesn't always work.</p>
  <p>The width option is measured in average sized characters for the font, but the problem is that the size of a tab 'character' varies. The way the tab key works for the text widget is different than the print() functions for a terminal or text file.</p>
  <p>Here is my code below:</p>
  <pre><code>from tkinter import *
  import math
  
  
  class App(Text):
      def __init__(self, matrix, parent, **kwargs):
          Text.__init__(self, parent, **kwargs)
          self.parent = parent
          self.matrix = matrix
  
          temp = []
          for row in matrix:
              temp.append(len(row))
  
          # Making sure all the rows are of equal length and string values...
          for row in matrix:
              for _ in range(max(temp) - len(row)):
                  row.append('')
  
          matrix = [[str(matrix[r][c]) for c in range(len(matrix[0]))] for r in range(len(matrix))]
          
          # I need to get the maximum length for each column in the matrix...
          c_lengths = {}
          for c in range(len(matrix[0])):
              c_lengths.update({c: []})
              for r in range(len(matrix)):
                  c_lengths[c].append(len(matrix[r][c]))
  
          self.tab_list = []
          for r in range(len(matrix)):
              temp = []
              for c in range(len(matrix[0])):
                  if c != len(matrix[0]) - 1:
                      tab_count = (math.floor(max(c_lengths[c])/8)+1)
                      '''if (tab_count + max(c_lengths[c])) % 8 == 0:
                          tab_count += 1'''
                      temp.append(tab_count)
                      tabs = ['\t'] * tab_count
                      string = matrix[r][c] + ''.join(tabs)
                  else:
                      string = matrix[r][c]
                  self.insert(END, string)
              self.tab_list.append(sum(temp))
              self.insert(END, '\n')
  
          self.configure(state=DISABLED, wrap=NONE, width=self.get_width())
  
      def get_width(self):
          temp = []
          for row in self.matrix:
              temp.append(len(''.join(row)))
          return max(temp) + max(self.tab_list)*4
  
  
  if __name__ == '__main__':
      import random
      root = Tk()
      root.state('zoomed')
  
      m = [['0' for _ in range(5)] for _ in range(40)]
  
      for i in range(40):
          for j in range(5):
              m[i][j] = '*' * random.randint(1, 25)
  
      App(m, root, font=('Times', '12'), height=40).pack()
      root.mainloop()
  
  </code></pre>
  <p>Here is the output:
  <a href="https://i.stack.imgur.com/63xrF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/63xrF.png" alt="enter image description here" /></a></p>
  <p>This run worked out good, but sometimes it cuts off some of the table.</p>