10

I need a simple way to render HTML pages retrieved with Requests (python-requests.org). I'm using Python 3.2 on Windows.

I was using tkinter, and I found a Tk widget called TkHtml. It is described at http://tkhtml.tcl.tk/ and a DLL is downloadable from http://www.hwaci.com/sw/tkhtml/. I found a python wrapper at http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py.

I don't know how to get TkHtml working in python. Is there some standard way of handling 3rd party Tk widgets?

I put tkhtml.dll in Python32\DLLs (no idea if this is right) and put TkHtml.py in Python32\Lib\site-packages. I went ahead and fixed the imports in TkHtml.py to work with Python 3 (changed tkFileDialog to tkinter.filedialog and Tkinter to tkinter).

When I do:

import TkHtml
app=TkHtml.TestApp()

I get the error:

...
File "C:\Program Files\Python32\lib\site-packages\TkHtml.py", line 45, in __init__
master.tk.call("package", "require", "tkhtml")
_tkinter.TclError: can't find package tkhtml

Any ideas?

Abbas
  • 6,720
  • 4
  • 35
  • 49
A Coder
  • 475
  • 1
  • 6
  • 16

3 Answers3

5

Find your Python tcl directory eg. C:\Python32\tcl . This is where tcl/tk extensions go.

Create a new folder in there called Tkhtml.

Into this folder put (1) your .dll file , (2) a text file called pkgIndex.tcl

pkgIndex.tcl contains a line like this:

package ifneeded Tkhtml 0.0 [list load [file join $dir tkhtml.dll]]

If you can do this at the python prompt,

>>> import Tkinter #tkinter
>>> root = Tkinter.Tk()
>>> root.tk.eval('package require Tkhtml')
'0.0'

... then the package is available. The string '0.0' represents the version number.

martineau
  • 119,623
  • 25
  • 170
  • 301
noob oddy
  • 1,314
  • 8
  • 11
5

I created a pip-installable Python wrapper for Tkhtml3: https://bitbucket.org/aivarannamaa/tkinterhtml

It comes with TkHtml3 binaries for Windows, Mac and Linux.

Aivar
  • 6,814
  • 5
  • 46
  • 78
2

I am using Python 3.3 on Windows 8 (64-bit) and received the same package load error as the OP.

I too had downloaded and saved TkHtml .dll and .py files to these following folders:

tkhtml.dll -> D:\Python3.3\DLL
TkHtml.py -> D:\Python3.3\Lib\site-packages

Based on noob oddy's suggestion, I did the following:

tkhtml.dll -> D:\Python3.3\tcl\Tkhtml
pkgIndex.tcl -> D:\Python3.3\tcl\Tkhtml

And copied this line: package ifneeded Tkhtml 0.0 [list load [file join $dir tkhtml.dll]] into the pkgIndex.tcl file.

What finally did the trick for me was moving everything from Python3.3 folder to Python2 folder. The HTML renderer worked beautifully. It seems that TkHtml is not be compatible with Python 3.

Abbas
  • 6,720
  • 4
  • 35
  • 49