4

I have a simple Tkinter app in Python. I'd like to add help document to it; what is the simplest way to integrate an help viewer to the app? Preferably cross-platform (although I primarily use Windows)?

I can imagine writing the help in plain HTML.

3 Answers 3

4

Or just launch an external web browser, using the webbrowser module from the standard library.

import webbrowser
webbrowser.open('/path/to/help/file.html')

For writing your documentation, have a look at sphinx.

Sign up to request clarification or add additional context in comments.

2 Comments

I didn't ask this in the original question, but one advantage of using a native help viewer is the search functionality. I believe sphinx has a json-based search; and that should probably meet my modest needs. Thanks
Be aware that the doc for webbrowser says (re. the open function): Note that on some platforms, trying to open a filename using this function, may work and start the operating system’s associated program. However, this is neither supported nor portable.
2

You could stick with writting in html, and then using something like this: Tkhtml which displays html pretty well and is fairly lightweight. :)

And here is the python wrapper. I hope this helps.

2 Comments

Here is a newer, pip-installable Python wrapper: bitbucket.org/aivarannamaa/tkinterhtml. It comes with TkHtml3 binaries for Windows, Mac and Linux.
tkinterhtml is no longer supported.
1

I found that package tkinterweb (https://pypi.org/project/tkinterweb/) provides HtmlFrame that will display HTML. I wanted to used markdown - Python-Markdown (https://python-markdown.github.io/) converts markdown into HTML, so I used both. Both are pip-installable.

pip install markdown
pip install tkinterweb

Here's some sample code:

import tkinter as tk
from tkinterweb import HtmlFrame
import markdown
import tempfile

root = tk.Tk()
frame = HtmlFrame(root, messages_enabled=False)

m_text = (
    'Markdown sample (https://en.wikipedia.org/wiki/Markdown#Examples)\n'
    '\n'
    'Heading\n'
    '=======\n'
    '\n'
    'Sub-heading\n'
    '-----------\n'
    '\n'
    '# Alternative heading #\n'
    '\n'
    'Paragraphs are separated\n'
    'by a blank line.\n'
    '\n'
    'Two spaces at the end of a line  \n'
    'produce a line break.\n'
    '\n'
    'Text attributes _italic_, **bold**, `monospace`.\n'
    '\n'
    'Horizontal rule:\n'
    '\n'
    '---\n'
    '\n'
    'Bullet lists nested within numbered list:\n'
    '\n'
    '  1. fruits\n'
    '     * apple\n'
    '     * banana\n'
    '  2. vegetables\n'
    '     - carrot\n'
    '     - broccoli\n'
    '\n'
    'A [link](http://example.com).\n'
    '\n'
    '![Image](Icon-pictures.png "icon")\n'
    '\n'
    '> Markdown uses email-style\n'
    'characters for blockquoting.\n'
    '>\n'
    '> Multiple paragraphs need to be prepended individually.\n'
    '\n'
    'Most inline <abbr title="Hypertext Markup Language">HTML</abbr> is supported.\n'
)

'''
# normally read the text from a file
with open('sample.md', 'r') as f:
    m_text = f.read()
'''
m_html = markdown.markdown(m_text)
temp_html = tempfile.NamedTemporaryFile(mode='w')
f = open(temp_html.name, 'w')
f.write(m_html)
f.flush()
frame.load_file(f.name)
frame.pack(fill="both", expand=True)
root.mainloop()

If you compare the generated HTML from markdown with that in the Wikipedia entry you can see it does a cracking job. However, HtmlFrame not so, but probably good enough for basic documentation.

Update: I discovered that tkinterweb is based on tkhtml, so this solution does suffer some of the same deficiencies as others posted here.

3 Comments

What deficiencies are there exactly?
At least two I've found: <code> is rendered in normal type, not monospace, and a 2nd level <ul> is rendered as <ol>.
Try re-installing TkinterWeb. I can't seem to reproduce your issue with <code>, but I just fixed the issues with <ul>. Thanks for letting me know about this, and if you notice any other deficiencies please feel free to report them on the Github page!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.