By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

Problems with redrawing tables

P: 3
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:
----------

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from tktable import *
  3. from time import *
  4.  
  5. root = Tk()
  6.  
  7. var = ArrayVar(root)
  8.  
  9. t = Table(flashmode=1,variable=var)
  10. for z in range(10):
  11.         for y in range(10):
  12.                 for x in range(10):
  13.                         index = "%i,%i" % (y, x)
  14.                         index2 = "%i,%i" % (z*y, z*x)
  15.                         var[index] = index2
  16.  
  17.         t.variable = var
  18.         t.pack()
  19.         sleep(1)
  20.         print "... "
  21.  
  22.  
  23. root = Tk()
  24.  
  25. root.mainloop()
  26.  
Apr 29 '11 #1
Share this Question
Share on Google+
4 Replies


P: 3
Oops, the indentation really is correct. It just did not show up in the example above when I cut and pasted.
Apr 29 '11 #2

Expert 100+
P: 621
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.
Apr 29 '11 #3

Expert 100+
P: 621
Your code the way that it appears to be indented
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from tktable import *
  3. from time import *
  4.  
  5. root = Tk()
  6.  
  7. var = ArrayVar(root)
  8.  
  9. t = Table(flashmode=1,variable=var)
  10. for z in range(10):
  11.     for y in range(10):
  12.         for x in range(10):
  13.             index = "%i,%i" % (y, x)
  14.             index2 = "%i,%i" % (z*y, z*x)
  15.             var[index] = index2
  16.  
  17. t.variable = var
  18. t.pack()
  19. sleep(1)
  20. print "... "
  21.  
  22.  
  23. root = Tk()
  24.  
  25. root.mainloop() 
Apr 29 '11 #4

P: 3
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.
Apr 29 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.