A html binding to Tkinter UI
Project description
PythonPresentationFoundation
Description:
Python Presentation Foundation allows the use of html and css to design and style UI for the purpose of use within tkinter.
The binding between both html and tkinter is done using tkinterweb. All events are currently handled by url requests.
An event system built in to the py_presentation_forum.Handle
class allows to bind python functions to urls.
Arguments can be passed through the requests from the html side.
Installation
pip install py-presentation-foundation
https://pypi.org/project/py-presentation-foundation/#description
Getting started
Create a directory with two files, a main.py
, and a config.json
. Create a directory for your html files to keep things clean.
Create an index.html file within
Directory|
|-->main.py
|-->config.json
|-->Design|
|-->index.html
# main.py
from py_presentation_forum import Handle
from py_presentation_forum.Utils import Utils
global hnwd
global conf
conf = Utils().getConfig("./config.json")
hnwd = Handle(conf)
hnwd.win.mainloop()
{
"url": "file:///C:/{...path}/Design/index.html"
}
You can aquire the [url]
path by viewing the html file in a browser and proceeding to copy the link from the url bar.
Events
There are two type of events, one that is triggered when the request is sent, and one that is triggered after the request has finished rendering.
We can test this by using this script:
from py_presentation_forum import Handle
from py_presentation_forum.Utils import Utils
from tkinter import messagebox
global hnwd
global conf
conf = Utils().getConfig("./config.json")
hnwd = Handle(conf)
class evnts:
def alert(args):
messagebox.showwarning(args[1], args[2])
def alert_done(args):
global hnwd
global conf
hnwd.frame.load_file(conf["url"])
hnwd.routes.newEvent(evnts, "alert")
hnwd.routes.newOnDone(evnts, "alert_done")
hnwd.win.mainloop()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<a href=";alert;test;hello world" class="button is-info">Info</a>
</body>
</html>
Request paths must contain a semi column ;
.
In this case we want to call an event called alert
.
Therefore we can call the function by using a hyperlink specifying the request route.
for example:
<a href=";alert">Test</a>
This would call the alert function. If we need to pass arguments to the alert function, we can do so as such:
<a href=";alert;arg1;arg2">Test</a>
if an onDone
event has been passed with the prefix of the primary functions name, then the onDone
event will be called automatically.
In the examples case, we use alert to show a warning box, and the alert_done to redirect back to the home page index.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-presentation-foundation-1.0.1.tar.gz
.
File metadata
- Download URL: py-presentation-foundation-1.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4125e422dc02ab8ef4bb5acec0c9c3b52af469a74cc97e3e00668e1fa440c381 |
|
MD5 | 4e57916eb57519fae448ae3ecd5bc848 |
|
BLAKE2b-256 | 176dcdc8f6a53907925269c1454bdd95ec7783f99b92a6f9fdff53c43a975307 |
File details
Details for the file py_presentation_foundation-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: py_presentation_foundation-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52df03dc2caf6ffb2e7d6dacf6d85608c09bc1479269bf99d7a1ed6cc0ea8852 |
|
MD5 | 6f7900b9a1e9edd3b85b7fe245e9f429 |
|
BLAKE2b-256 | 78461fbe00efb85430a16bacb963ca01ddb71fa21951dd7222c89f397d73645c |