TkinterWeb provides a handful of functions that allow for manipulation of the webpage. They are fashioned after common JavaScript functions.
To manipulate the Document Object Model, use yourframe.document
(new since version 3.25). For example, to create a heading inside of a container with the id 'container', one can use the following:
yourframe = tkinterweb.HtmlFrame(root)
yourframe.load_html("<div id='container'><p>Test</p></div>")
container = yourframe.document.getElementById("container")
new_header = yourframe.document.createElement("h1")
new_header.textContent("Hello, world!")
container.appendChild(new_header)
Create a new HTML element with the given tag name
Parameters
- tagname (string) - Specifies the new element's HTML tag
Return type
- HtmlElement
Create a new text node with the given text conent
Parameters
- text (string) - Specifies the text content of the new node
Return type
- HtmlElement
Return the document's body element
Return type
- HtmlElement
Return an element given an id
Parameters
- query (string) - Specifies the element id to be searched for
Return type
- HtmlElement
Return a list of elements given a class name
Parameters
- query (string) - Specifies the class name to be searched for
Return type
- HtmlElement
Return a list of elements matching a given name attribute
Parameters
- query (string) - Specifies the name to be searched for
Return type
- list
Return a list of elements matching a given tag name
Parameters
- query (string) - Specifies the tag name to be searched for
Return type
- list
Return the first element that matches a given CSS selector
Parameters
- query (string) - Specifies the CSS selector to be searched for
Return type
- HtmlElement
Return a list of elements that match a given CSS selector
Parameters
- query (string) - Specifies the CSS selector to be searched for
Return type
- list
Get and set the inner HTML of an element
Parameters
- contents (string) - If provided, specifies the new HTML content of the element
Return type
- string
Get and set the text content of an element
Parameters
- contents (string) - If provided, specifies the new text content of the element
Return type
- string
Get the value of the given attribute
Parameters
- attribute (string) - Specifies the element's attribute to return
Return type
- string
Set the value of the given attribute
Parameters
- attribute (string) - Specifies the element's attribute to set
- value (string) - Specifies new value of the specified attribute
Return type
- string
Get the tag name of the element
Return type
- string
Get and set the value of the given CSS property
Parameters
- property (string) - Specifies the element's CSS property to set
- value (string) - If provided, specifies new value of the specified property
Return type
- string
Get the element's parent element
Return type
- HtmlElement
Get the element's children elements
Parameters
- deep (boolean) - If False, only return the element's direct children. If True, return all children.
Return type
- list
Delete the element
Insert the specified children into the element
Parameters
- children (list or HtmlElement) - Specifies the element(s) to be added into the element
Insert the specified children before a specified child element
Parameters
- children (list or HtmlElement) - Specifies the element(s) to be added into the element
- before (HtmlElement) - Specifies the child element that the added elements should be placed before
Please report bugs or request new features on the issues page.