Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show markdown format text in tkinter?

In python-3.x with tkinter GUI, I developed a program with a regular simple window.

I want to show a markdown format string saved in a string called markdownText on program window:

markdownText='_italic_ or **bold**'

desired output is:

italic or bold

Is there any solution?

like image 385
Woeitg Avatar asked Mar 01 '16 20:03

Woeitg


People also ask

How do I read a .md file in Python?

You use the open() function to open the Picnic.md file; passing the value 'r' to the mode parameter to signify that Python should open it for reading. You save the file object in a variable called f , which you can use to reference the file. Then you read the file and save its contents inside the text variable.

How do you write Markdown in Python?

To add a Python code chunk to an R Markdown document, you can use the chunk header ```{python} , e.g., ```{python} print("Hello Python!") ```

What is markdown string?

Markdown is a lightweight markup language. It is used to add formatting elements to plain text documents. It is one of the most popular markup languages in the world. When creating a Markdown string, you add Markdown syntax to your text to indicate which words and phrases should look different.

What is Tk () in tkinter programming?

The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, including macOS, as well as on Windows systems.


1 Answers

I was just searching for a similar solution, and it does indeed not seem like there is a default module/class/library for the combination of Python, TkInter and markdown. However a continued search revealed the following options:

  • Python-Markdown – This a module capable of parsing markdown into the following output formats: Python-Markdown can output documents in HTML4, XHTML and HTML5.
  • TkInter displaying html – As the linked answer indicates, Tkhtml can display html "pretty well", and it has a python wrapper

In other words, if you are willing to use an intermediate step of converting into html that might be a viable route for you to display markdown strings within a tkinter GUI.

like image 129
holroy Avatar answered Oct 19 '22 18:10

holroy