Customizing TkHtml (Tk Widget) Using Python

I need an easy way to render HTML pages retrieved using queries ( python-requests.org ). I am using Python 3.2 for Windows.

I used tkinter, and found a Tk widget called TkHtml. It is described in http://tkhtml.tcl.tk/ , and the DLL can be downloaded from http://www.hwaci.com/sw/tkhtml/ . I found the python shell at http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py .

I don't know how to get TkHtml to work in python. Is there a standard way to handle third-party Tk widgets?

I put tkhtml.dll in Python32 \ DLL (I don't know if this is correct) and put TkHtml.py in Python32 \ Lib \ site-packages. I went ahead and fixed the import in TkHtml.py to work with Python 3 (changed tkFileDialog to tkinter.filedialog and Tkinter to tkinter).

When I do this:

import TkHtml app=TkHtml.TestApp() 

I get an error message:

 ... 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?

+8
python tkinter tk html-rendering
source share
3 answers

Find your tcl directory in Python, for example. C: \ Python32 \ tcl. This is the tcl / tk extension.

Create a new folder called Tkhtml.

Put (1) yours in this folder. DLL file, (2) pkgIndex.tcl text file

pkgIndex.tcl contains a line similar to 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.

+4
source share

I created a Python install shell for Tkhtml3: https://bitbucket.org/aivarannamaa/tkinterhtml

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

+4
source share

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

I also downloaded and saved the TkHtml .dll and .py files to the following folders:

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

Based on the noob oddy 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]] to the pkgIndex.tcl file.

Which, in the end, helped me move everything from the Python3.3 folder to the Python2 folder. HTML rendering worked beautifully. It seems that TkHtml not compatible with Python 3.

+2
source share

All Articles