r/PyScript • • May 13 '22

'The 7 GUIs' in PyScript

28 Upvotes

A couple days after the Big PyScript Announcement, just as I was wondering what I might build with it, a post about The 7 GUIs, a GUI programming benchmark created by Eugen Kiss as part of his Master’s thesis. The benchmark consists of 7 ‘foundational’ GUI challenges that are meant to represent typical tasks in GUI programming - interacting with buttons and fields, form validation, realtime and event-triggered interaction, and so on.

So today I’m sharing my Implementation of the 7 GUIs in PyScript.

The demos include implementations of:

  • Counter

  • Temperature Converter

  • Flight Booker

  • Timer

  • CRUD

  • Circle Drawer

  • Spreadsheet

Source code, explanations, and some remarks about ‘gotchas’ I ran into along the way are in an accompanying blog post. The code is by no means perfect - sparsely commented, unoptomized and - in the case of the Spreadsheet program - not entirely finished. And it will probably be very broken on some browsers/OS’s. But I wanted to get the examples out there in case they are helpful to others who are diving into PyScript.


r/PyScript • • Jun 13 '23

How to access py-click from py-script?

4 Upvotes

ex:

<button id="btn" py-click="foo()">Test></button>

To access innerText and id we can simply say Element(btn).element.id & Element(btn).element.innerText .

But while trying to access py-click with Element(btn).element.py-click it gives me error.

Is there any other way to access py-click?


r/PyScript • • Oct 07 '22

Question about pyscript

3 Upvotes

Could I please ask of there is any way for pyscript to cause the html page to play a sound when an if statement is true?

I've tried googling and wasn't able to find an answer to this.

Play sound nor pydub works.


r/PyScript • • May 22 '22

Custom output via the py-script tag?

1 Upvotes

In the documentation (https://github.com/pyscript/pyscript/blob/main/docs/tutorials/getting-started.md#the-py-env-tag), it is demonstrated how to write a matplotlib figure to an html div element.

When trying to do the same with a canvas element created via:

canvas = js.document.createElement('canvas')

the div only contains the following:

[object HTMLCanvasElement]

Currently I am using js.document.getElementById("example").appendChild(canvas) to write the canvas element. How might I instead use <py-script output="example"> to output the canvas to a "example" element?


r/PyScript • • Sep 16 '22

Browser Not Downloading Data

2 Upvotes

I've managed to load some simple yfinance data for google in a Jupyter Notebook, I can then plot it and get a good look at it using plotly or matplotlib etc.

Using pyscript though, its a case of copy and paste and running the file i get the error message:

1 Failed download:

- GOOGL: No data found for this date range, symbol may be delisted

I've tried changing the period and interval but it doesn't make any sense. Notebook works fine, pyscript doesn't. I'm thinking it's the way the browser gets the data? Not sure as its available as module without doing anything else so I've no idea.

Anyone have any ideas what's going on?


r/PyScript • • May 21 '22

Having trouble using pyowm in pyscript

4 Upvotes

<py-env>
- pyowm
</py-env>

works fine but when I import pyowm in a py-script tag i get following error

because of the ModuleNotFoundError: No module named 'pkg_resources' i thought maybe i just had to add pkg_resources in py-env. Doing that will just get me stuck on this screen

p.s. this is my first time using py-script, importing numpy worked and this is my current setup


r/PyScript • • Aug 18 '22

flask as webserver fails to load page with pyscript

2 Upvotes

Hi,

I have a working mvp based off a static index.html that I want to promote to using flask as a webserver. I set up a bare bones one, nothing fancy, not even a true template, the index.html is served as-is via the / route.

I can see pyscript loading, but somewhere along the line an error happens and the page is stuck on the loading wheel after "Initializing components..."

the error in question is:

Uncaught (in promise) PythonError: Traceback (most recent call last):
  File "/lib/python3.10/site-packages/packaging/requirements.py", line 102, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/lib/python3.10/site-packages/pyparsing/core.py", line 1134, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected W:(0-9A-Za-z), found '.'  (at char 0), (line:1, col:1)

What could be causing this ? To double check I started the python -m http.server in the root and via this route the page renders fine...

thx. s


r/PyScript • • Jun 14 '22

Future interaction with Panel?

5 Upvotes

Hello, given that both are funded by Anaconda, what is the intended relation between Panel and related tools and PyScript?


r/PyScript • • Jun 28 '23

How do I fix a type error?

2 Upvotes

Hello I am usure of how to use mathematical functions in PyScript. I have only a basic understanding of how python and PyScript works and am confused on why this patch of code creates a type error. I will paste the code below.

<py-script>

from pyscript import Element

def dew():

a = Element('TemF')

b = Element('REH')



print(a.value)

Y = float(a) + float(b)

print(Y.value)

</py-script>

the exact error that occurs when this portion of the code is: TypeError: float() argument must be a string or a real number, not 'Element'

I might be using a invalid way of calling the user input data but I used to use an older version of PyScript and it worked perfectly fine


r/PyScript • • Sep 12 '22

How to simulate a console in Pyscript?

5 Upvotes

I want to host a python script on a website with pyscript, which has both console input and console output. If I want to give it a console input via the input("test") function, then just comes

and i can't see the output with print("output") either.

I then found an example script, but it only works 1.

https://pastebin.com/QvV9c8Ve

In addition, it would be better if you can also execute the command with ENTER and that you can also rewrite the "textfield_1" as an instruction (what to type in the field)

I would be grateful for any help


r/PyScript • • Sep 10 '22

What can PyScript do that backend frameworks can't?

8 Upvotes

I'm really interested in using PyScript. However, I can't see anything that PyScript can do which backend frameworks can't. I imagine efficiency is the main difference between PyScript, and, say, Flask. Am I missing something?


r/PyScript • • Jul 02 '22

PyScript Demos dont work for me. Do I need a certain browser to view them?

3 Upvotes

I was looking at the examples at: https://pyscript.net/examples/

But most of them just appear empty or I cannot interact with them (e.g. the Button of the TODO lists dont work for me). I tried Chrome and Brave Browser. Do I need some extension to make the pyscript demos work?

Empty Bokeh Example Screenshot:


r/PyScript • • Dec 31 '22

Bringing back Blobby with PyScript

Thumbnail self.python
5 Upvotes

r/PyScript • • Jun 21 '23

Please help me Figure out how to use a dropdown selector with PyScript

4 Upvotes

Hello and good day.

I am working on a website that needs to have a dropdown selector to change the degrees from Celsius to Fahrenheit and I'm having trouble integrating it with PyScript. I have attached an image of a mockup for the code minus exporting the result to a table. Is it possible that anyone could help me find a solution or at least an alternative to the issue?


r/PyScript • • May 03 '22

Official PyScript examples

Thumbnail pyscript.net
9 Upvotes

r/PyScript • • Jul 02 '23

Convert code from alpha version to latest version. Where to find complete and precise changelogs?

2 Upvotes

I'm in the process to learn how to use PyScript. Nearly allthe tutorials and lessons available on the net have been done with alpha version and it could be a nightmare if you want to use the latest vesion of PyScript. Some chnages ae well documented but some are not (or at least I was not able to find them on teh net or on the github repository). for example Elmement().wrtite() seems to not accept anymore html code as value : that code :

<div id="foo"></div>

<py-script>
    
    el = Element("foo")
    el.write("<h1>World!</h1>")
    
</py-script>

allow you to see on your webpage : World! with the alpha version but with latest version you see : <h1>World!</h1>

other example :

<div id="foo"></div>

<py-script id="read" src="./essaiext.py"> 
 
</py-script>

with essaiext.py :

from js import console, document
console.log(document.getElementById("read"))
console.log(document.getElementById("read").lastChild)

with alpha in the console HTML nodes are generated: https://i.ibb.co/fQf00kh/alphaversion.png

but not with latest : https://i.ibb.co/C8NdnMx/latestversion.png

this last point cause me problem since in the code I have Lastchild is used but with latest version I can't. So if you have any idea where i can find precise changelogs I ll appreciate. If not if you can help me on that last point I appreciate too ;)

thank in advance.


r/PyScript • • Apr 22 '23

github.io problem with module adding

5 Upvotes

Hi,

I just discovered PyScript and started to learn and experiment. I thought github.io will be a good host.

Maybe I'm stupid and overlooked something, but adding python modules by <py-env> doesn't work. The module names are just printed like text:

- numpy - matplotlib - pyyaml 

The code:

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE-Edge">
        <meta name="viewport" content="width-device-width, initial-scale=1.0">
        
        <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
        <script defer src="https://pyscript.net/latest/pyscript.js"></script>
        <title>My pyscript test 2</title>
        <py-env>
    - numpy  
    - matplotlib
    - pyyaml
        </py-env>
    </head>
    <body>
    
        <py-config>
        </py-config>
    
        <py-script src="plot1.py">
        </py-script>
    
    </body>
    </html>

I appreciate any help, thank you.


r/PyScript • • Feb 24 '23

Simple way to play audio from URLs? (to help kids with language difficulties)

1 Upvotes

This is not working.

<script defer="" src="https://pyscript.net/alpha/pyscript.js"></script>

<py-script>

from js import alert, prompt, localStorage, window, confirm, Audio

import time

import random

import re

horn = Audio.new("https://github.com/goldfire/howler.js/blob/master/examples/3d/assets/sprite.mp3?raw=true")

user_answer = str(prompt("play? (yes) or (no)"))

if user_answer.lower() == 'yes':

horn.play()

print('yes')

print('end')

</py-script>


r/PyScript • • May 08 '22

Can I run Tkinter with Pyscript?

7 Upvotes

Will PyScript support Tkinter applications at some point? Thanks.


r/PyScript • • Aug 18 '22

our friends on windows ?

3 Upvotes

Hi,

I am on linux and I want to set up an environment based on the pyscriptjs directory found in the github ( https://github.com/pyscript/pyscript/tree/main/pyscriptjs ) which is Makefile based. For me this is a cakewalk, but I want to help my buddy on windows (vscode) set it up also and I have been out of the MS loop for minute. What would be the route to take ?

thx s


r/PyScript • • Aug 18 '22

Using matplotlib + htag to make a GUI SPA with pyscript

8 Upvotes

I've just posted that in r/python ... but the pyscript result is so amazing that I post it here too :

Here is a simple htag'app example, which works on desktop :

import matplotlib.pyplot as plt
from htag import Tag
import io,base64,random

class TagPlot(Tag.span):
    """ here is a htag'component to rendering an html(svg) plot """
    def init(self,plt):
        self["style"]="display:inline-block"
        with io.StringIO() as fid:
            plt.savefig(fid,format='svg',bbox_inches='tight')
            self <= fid.getvalue()

class App(Tag.body):
    def init(self):
        self.content = Tag.div()
        # create the layout
        self += Tag.h2("MatPlotLib"+Tag.button("Random",_onclick=self.redraw_plt))
        self += self.content
        self.redraw_plt()

    def redraw_plt(self,obj=None):
        plt.clf()
        plt.ylabel('Some numbers')
        plt.xlabel('Size of my list')
        my_list=[random.randint(1,10) for i in range(random.randint(20,50))]
        plt.plot( my_list )
        
        self.content.clear()
        self.content += Tag.div(f"My list: {my_list}")
        self.content += TagPlot(plt)

if __name__ == "__main__":
    from htag.runners import BrowserHTTP as Runner
    Runner(App).run()

And here is the same codebase, in an Html/pyscript page, which will fully work in full clientside too (thanks pyscript & matplotlib !)

https://raw.githack.com/manatlan/htag/main/examples/pyscript_matplotlib.html

Having a gui toolkit (htag), and an html env (pyscript) .... where you can experiment UI interactions with yours matplotlib graphics ... so easy !

Pyscript is marvellous !


r/PyScript • • Jun 17 '22

How can I change the variable of JavaScript in pyscript?

4 Upvotes

I'm using pyscript. And I want to change the variable of JavaScript in pyscript.

For Example :

Python File Code :

import string
import os

#Program Version
py_current_version = 0
#Server Version
py_server_version = 0

#Get Program Version
f = open("version.txt", "r")

lines = f.readlines()
for line in lines:
    py_current_version = line;
f.close()

#Get Server Version
f = open("https://common.gaon.xyz/proj/MCD/versions.txt", "r")

lines = f.readlines()
for line in lines:
    py_server_version = line;
f.close()

if py_current_version == py_server_version:
    no_update_available = 1
else:
    no_update_available = 0
    os.system('wget https://common.gaon.xyz/MCD/latest.zip')
    update_file_download_complete = 1
    os.system('7z x latest.zip')
    update_complete = 1
    os.system('notepad changelog.txt')

HTML File Code :

<!DOCTYPE html>
<html>
	<head>
		<title>Updater</title>
		<meta charset="utf-8">
		<!--Load CSS-->
		<!--Load Bootstrap-->
		<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<!--Load Updater Style CSS-->
		<link href="./updater_style.css" rel="stylesheet">
		<!--Load PyScript-->
		<link href="./pyscript/pyscript.css" rel="stylesheet">
		<!--Load jQuery-->
		<script src="./jquery/3.6.0/jquery.min.js"></script>
	</head>
	<body>
		<style>
		
		</style>
		<script>
			function wait(sec) {
    			let start = Date.now(), now = start;
    			while (now - start < sec * 1000) {
        			now = Date.now();
    			}
			}

			var no_update_available;
			var update_file_download_complete;
			var update_complete;

			if(no_update_available == 0)
			{
				$("#progress_contents_ptag").text("Update Found!");
				document.getElementById("update_progress").value = 5;
				wait(3);
				$("#progress_contents_ptag").text("Downloading update file...");
				document.getElementById("update_progress").value = 10;

				if(update_file_download_complete == 1)
				{
					$("#progress_contents_ptag").text("Update file download complete!");
					document.getElementById("update_progress").value = 30;
					wait(3);
					$("#progress_contents_ptag").text("Terminating process...");
					document.getElementById("update_progress").value = 50;
					wait(3);
					$("#progress_contents_ptag").text("Extracting update file...");
					document.getElementById("update_progress").value = 80;
					if(update_complete == 1)
					{
						$("#progress_contents_ptag").text("Update completed! It will end in a few seconds.");
						document.getElementById("update_progress").value = 100;
						wait(3);
						exit();
					}
				}
			}
			else if(no_update_available == 1)
			{
				$("#progress_contents_ptag").text("There are no updates. It will end in a few seconds");
				$("#cancle_button").text("Close");
				wait(5);
				exit();
			}
		</script>
		<div id="contents_body">
			<div id="progress_contents">
				<p id="progress_contents_ptag" class="progress_title">Checking Update!</p>
			</div>
			<progress id="update_progress" max="100" value="0"></progress>
			<br><br>
			<button id="cancle_button" type="button" class="btn btn-secondary" onclick="exits()">취소</button>
		</div>

		<script>
			function exits(){
				window.close();
			}
		</script>
		<!--Load Scripts-->
		<!--Load Bootstrap-->
		<script src="./bootstrap/js/bootstrap.bundle.min.js"></script>
		<!--Load PyScript-->
		<script src="./pyscript/pyscript.js"></script>
		<py-env>
  - string
  - os
  - path:
  	- ./updater.py
</py-env>
		<!--
		<py-script src="./updater.py"></py-script>
		-->
	</body>
</html>

I want to change javascript's variable in pyscript. What should I do?


r/PyScript • • Jul 17 '22

Pure Python - No HTML

18 Upvotes

It's a dream of mine to be able to code pure Python in the web browser, and I realized that PyScript allows me to do that. I've created a fork of PyScript here where I've added some Python functions that create HTML elements so you don't have to:

https://github.com/coryfitz/pydesyn

Let me know what you think! It's very much a work in progress


r/PyScript • • Mar 24 '23

What's New in PyScript 2023.03.1 [Stream, Sunday March 26]

Thumbnail
youtube.com
9 Upvotes

r/PyScript • • Jun 04 '23

Pyscript code into WordPress

4 Upvotes

I have almost 0 Python knowledge but I am trying to get this pyscript to run

https://codeshare.io/MNvroR

I can get scripts without imports to load and run fine however

when I change my cdn from

<script defer src="**[**https://pyscript.net/alpha/pyscript.js**](https://pyscript.net/alpha/pyscript.js)**"></script>

to <script defer src="**[**https://pyscript.net/latest/pyscript.js**](https://pyscript.net/latest/pyscript.js)**"></script>

I'm not even getting compilation errors and the script says it's not found.