5

I'm trying to import tktable to create a simple table, but I'm getting the error below:

File "prob.py", line 7, in import tktable ImportError: No module named tktable

from tkinter import *
import tktable

root = Tk()
root.title("Probabilidade e estatistica")

table = tktable.Table(root, rows=2, cols=10)
table.pack()

root.mainloop()
nbro
  • 15,395
  • 32
  • 113
  • 196
João Victor
  • 81
  • 1
  • 1
  • 7

2 Answers2

2

tktable isn't part of the standard tkinter package, meaning it's not a built-in feature.

You can download the tktable package from the Sourceforge website.

nbro
  • 15,395
  • 32
  • 113
  • 196
SkyDrive26
  • 191
  • 2
  • 3
  • 8
0

tktable does not come with the Python standard distributions, unfortuntely. Thus, you need to download and copy it to your working directory or put it under the site-packages folder of your Python distribution.

tktable is a wrapper library around the homonymous library for the Tcl language and its Tk GUI toolkit. It was written by Guilherme Polo (the guy who wrote ttk). It supports images, embedded windows, varying colors and fonts, and more.

You can download a version of tktable which supports both Python 3 and Python 2 from this GitHub repository, where you can find other information on how to use it. A version for Python 2 is also available here. If you need a complete reference of all supported options, the ActiveState documentation on the Tcl/Tk TkTable might be the best way to go for now.

nbro
  • 15,395
  • 32
  • 113
  • 196
  • I've installed it locally, etc. but it seems TkTable (the Tcl/Tk part) is unmaintained, and has been removed from repos. I'm a little wary if I should actually use the old and unmaintained TkTable implementation and wing it from there... – polemon May 19 '15 at 08:46
  • @polemon I suppose that the ActiveState version of Tcl/Tk's `tktable` is maintained, but you better ask for a precise answer on their forums. – nbro Jan 15 '17 at 20:05
  • This doesn't work in Python 3, I get this message: "_tkinter.TclError: invalid command name "table"". – Lars Ericson Jan 09 '18 at 18:11
  • @LarsEricson What doesn't work? Have you first installed the underlying Tk library called `tktable`? – nbro Jan 09 '18 at 18:31
  • There is no underlying tktable for Python 3.4, according to pip. Also, it was complaining about "table", not "tktable". I used the tktable.py from [here](https://github.com/nbro/tktable), just ran python tktable.py, I didn't run setup because it seems there is only 1 file there. – Lars Ericson Jan 09 '18 at 20:18
  • @LarsEricson You should describe exactly your directory structure. – nbro Jan 09 '18 at 20:24
  • Actually per an answer below there is no standard distribution for tktable except on SourceForge, I will try to find it on [SourceForge](https://sourceforge.net/projects/tktable/).....and that's not so good, it gives a C source file I have to unpack twice and then figure out how to build, not so easy. – Lars Ericson Jan 09 '18 at 20:26
  • @LarsEricson That won't work either. The Python library you can find in the Github repository I am mentioning is exactly the same as the one on the Sourceforge website. I only introduced the possibility to make it work for both Python 2 and 3. – nbro Jan 09 '18 at 20:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162846/discussion-between-nbro-and-lars-ericson). – nbro Jan 09 '18 at 20:29
  • Sorry @nbro I think I will give up. The file on GitHub requires presence of tktable and I don't have an easy way to install tktable for Python 3.4 for Windows. – Lars Ericson Jan 09 '18 at 20:30