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?
Tk is a package that provides a rich set of graphical components for creating graphical applications with Tcl. Tk provides a range of widgets ranging from basic GUI widgets like buttons and menus to data display widgets. The widgets are very configurable as they have default configurations making them easy to use.
The tkhtmlview module is a collection of Tkinter widgets whose text can be set in HTML format. An HTML widget isn't a web browser frame, it's only a simple and lightweight HTML parser that formats the tags used by the Tkinter Text base class.
Tkinter ProgrammingImport the Tkinter module. Create the GUI application main window. Add one or more of the above-mentioned widgets to the GUI application. Enter the main event loop to take action against each event triggered by the user.
As you can see, you would be able to create your whole GUI using HTML, we just must add <script type="text/javascript" src="/eel. js"></script> , this script will allow us to call our exposed python functions. We have completed our graphical user interface, now, we must create our python file.
I created a pip-installable Python wrapper for Tkhtml3: https://bitbucket.org/aivarannamaa/tkinterhtml
It comes with TkHtml3 binaries for Windows, Mac and Linux.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With