Problems with redrawing tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Chamberlai
    New Member
    • Apr 2011
    • 3

    Problems with redrawing tables

    I am learning how to use tktable. I made a table and put some data in it which appeared. I want to put it into a loop and change the data 5 or 6 times. Right now I am just putting simple data in until I get it to work correctly, just to verify the tables is updated. Later I will put specific data.

    My problem though is, I create the array, fill it, pack it, then change the data, pack it, change, and then pack, but it only ever shows the last values that were in the array, not the earlier ones. I even put a sleep command to wait a few seconds between instances, and that prints. Does anyone know what I am doing wrong? Code is below. The sets of dots are printing every second. But it shows only one array with 9*row, 9*column. It should show the array change each time before the three dots (...) are printed.

    Code:
    ----------

    Code:
    from Tkinter import *
    from tktable import *
    from time import *
    
    root = Tk()
    
    var = ArrayVar(root)
    
    t = Table(flashmode=1,variable=var)
    for z in range(10):
            for y in range(10):
                    for x in range(10):
                            index = "%i,%i" % (y, x)
                            index2 = "%i,%i" % (z*y, z*x)
                            var[index] = index2
    
            t.variable = var
            t.pack()
            sleep(1)
            print "... "
    
    
    root = Tk()
    
    root.mainloop()
    Last edited by Niheel; Apr 29 '11, 08:26 PM.
  • Tony Chamberlai
    New Member
    • Apr 2011
    • 3

    #2
    Oops, the indentation really is correct. It just did not show up in the example above when I cut and pasted.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      I don't use or have tktable installed so can't test, but for starters you have two calls to Tk(), i.e. root=Tk() and that can't be good. Also, how does the table know the size since you don't supply the rows and columns when calling Table. Perhaps it can figure it out from the data but then when you add more data there is no room to display it since the table is the size of the original data.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        Your code the way that it appears to be indented
        Code:
        from Tkinter import *
        from tktable import *
        from time import *
        
        root = Tk()
        
        var = ArrayVar(root)
        
        t = Table(flashmode=1,variable=var)
        for z in range(10):
            for y in range(10):
                for x in range(10):
                    index = "%i,%i" % (y, x)
                    index2 = "%i,%i" % (z*y, z*x)
                    var[index] = index2
        
        t.variable = var
        t.pack()
        sleep(1)
        print "... "
        
        
        root = Tk()
        
        root.mainloop()

        Comment

        • Tony Chamberlai
          New Member
          • Apr 2011
          • 3

          #5
          I see your concern and you are correct. Right now I am just learning how to use the table. If you do not specify a row it defaults to 10. Same with columns. I will make it more robust later.

          I guess my question (or observation) really is that pack() does not happen until the end. Is that true? I mean you can pack your table several times, but only the last one will count since the display is done only once?

          By the way thanks for pointing out I forgot to delete one of the Tk() calls. I fixed it now but same problem.

          Comment

          Working...