Andereoo/TkinterWeb

Question/possible feature request: Node navigation

rodneyboyd opened this issue · 5 comments

We have access to the currently-hovered node, but what if it turns out not to be the one we want, and we need its parent, or parent's parent instead? Is there any way to get there? If not, could there be? Sorry if this is out of scope for this project, I wasn't sure how to ask a question without submitting an issue. Thanks.

Great question! The functions provided by HtmlFrame are simply convenience methods. They build on the framework set out in the underlying TkinterWeb widget, which is where you can access document nodes. Use yourframe.html to access this widget.

The currently hovered node itself (rather than its tag, text, or attributes) can be found via yourframe.html.current_node. Note that this is a variable and not a function. Pass this variable to yourframe.html.get_node_parent(node_handle) to get its parent node. Likewise, get_node_children(node_handle) will return all the children of a given node. Then, get_node_attribute(node_handle, attribute) and get_node_tag(node_handle), for instance, can be used to get information about your given node. Check out the source code for more functions you can use. This code gives you massive control over the document and how it displays. You can even replace or delete nodes.

Let me know if there is anything else regarding document nodes in particular that you need to find. There's a good chance I have a function somewhere that can help you accomplish it.

Thanks for this. I didn't really realize that we had access to this stuff. Maybe you should consider expanding the TkInterWeb docs. Right now it more or less says "here be dragons" :-)

I put a bit more content in the TkinterWeb docs. Let me know what you think. I can't hide those dragons, but maybe we can make it a bit easier to catch them.

Thanks for the new docs! What is the protocol here ... can loyal readers update the content or should we go through you?