'Display a graph generated by Graphviz in tkinter python

I wonder if there is a package or example that display graphs that are created by Graphviz using PyGraphviz, in tkinter

My investigation:

My graphs can be rendered in to images without a problem. In the documentation of Graphviz, under Output Formats I see that it is also capable to output as tk. It is descried as text-based Tcl/Tk graphics primitives. When I try setting the format in tk and render, it generates a .gv file and a .tk file. The .gv file simply saves the source in dot language. The .tk saves as something very similar to tkinter canvas methods.

Code:

graph = ... #some graph source
graph.format = 'tk'
graph.render()

.tk file looks like:

# Generated by graphviz version 2.49.3 (20211023.0002)
# Title: G Pages: 1
# node2513277377840
$c create polygon 122.6667 5.3333 56 5.3333 56 80 122.6667 80 -fill #fefecd -width 0.5 -outline #444443 -tags {1node0x244a1f84030}
$c create polygon 58.6667 26.6667 58.6667 8 120 8 120 26.6667 -fill #fefecd -width 1 -outline transparent -tags {0node0x244a1f84030}
$c create line 58.6667 26.6667 120 26.6667 -fill #444443 -tags {0node0x244a1f84030}
$c create text 60 17.95 -text {BSTNode} -fill #444443 -font {"Times" 11} -anchor w -tags {0node0x244a1f84030}
$c create polygon 58.6667 29.3333 58.6667 26.6667 120 26.6667 120 29.3333 -fill #fefecd -width 1 -outline transparent -tags {0node0x244a1f84030}
$c create polygon 58.6667 48 58.6667 29.3333 90.6667 29.3333 90.6667 48 -fill #fefecd -width 1 -outline transparent -tags {0node0x244a1f84030}
$c create line 90.6667 48 90.6667 29.3333 -fill #444443 -tags {0node0x244a1f84030}
...

Questions:

  1. How would a graph generated by graphviz usually be displayed in tkinter?

  2. Do I read and translate the .tk file to call corresponding methods in order for tkinter canvas to show the graph? Is that how it is meant to be done?

  3. Is it better off just display the generated image file (svg,png,bmp,jpeg)?

  4. Is there a way to do it without saving and reading files?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source