Rock, Paper Scissors - ’Game’ in Brython - Need some help

162 views
Skip to first unread message

Olof Paulson

unread,
Nov 13, 2021, 7:01:31 AM11/13/21
to brython
Hi Everyone 👋 

I was looking into making a tutorial of Rock,Paper, and Scissors , but got bored and started off by making a game instead...

Basically you try to beat the computer...
You see what the computer ’played’ ,and then you have a limited time to respond..
As points/ leve increases time gets shorter...
You lose a life if you are too slow or lose the game...
https://scrimba.com/scrim/co4354019bc865d33339f09fb

The game play UX is...well terrible... 💩 
All I use is the ’Input’ dialog which pops some ugly popup in browser...

I thought I could make the game-play nicer by making it a hybrid ( python + brython specific functions), but Haven’t figured out how to interact with a browser page properly yet..so that’s partly why I am posting. 😉 

Any suggestion ?
How would you make it nicer..?
Appreciate any assistance 🙏 

Olof

Pierre Quentel

unread,
Nov 19, 2021, 3:51:00 AM11/19/21
to brython
Hi Olof,

I have made a version that I could run in the Scrimba sandbox : https://gist.github.com/PierreQuentel/9688a10a0ac475470a1a334df928786c

For interaction it uses the dialog box provided in the builtin module browser.widgets.dialog and callback functions instead of blocking input().

Hope this helps,
Pierre

Olof Paulson

unread,
Nov 23, 2021, 3:18:23 AM11/23/21
to brython
Thank you so much Pierre, You are a star!
Your game looks so much nicer!
Will experiment a bit and see What I can learn and how to make the code as ’Python as possible’

Students seem to get nervous from mixing python/ HTML/ JS’ code
tendency seems to be to disengage from material ’I’m learning Pyton...Not this ’other stuff’ ’

I posted this ’Fix the broken code challenge - calculator’ the other day using your Brython calculator as a base , and got feedback about ’it’s not really python- I don’t want to mess with it’,
 from people who normally engage with challenges ...scrimba.com/scrim/co357414cbd5cc2f0ff6c053d ...
Is my ambition possible?
Ofcourse, I realise my Brython usecase is quite specific - ’ Teaching Python in a browser window on Scrimba’, and I am struggling to get past the basics, partly based on what Brython Supports.Largely due to my own coding level.

The goal, for me, is to create a suite of tutorials in Scrimba covering more and more python, so people can learn as much Python as possible in the interactive GUI of Scrimba( or if another service like it comes along)

(Have considered trying pyodide for matplotlib, numpy etc...but I can’t get it to work properly( i.e like Brython in Scrimba), and last time I tried a year ago it was was very slow. but right now nothing. I am failing at even connecting it to scrimba)

TKinter or other Python GUI packages?

Being able to trigger a ’Native Python gui’ like tkinter would be an example that I think learners would appreciate.
Is there a way to run tkinter or any of the other gui Packages with Brython/Scrimba or is a JS wrapper the more likely way(less python-y for me)?

Thank you very much as always!

Pierre Quentel

unread,
Nov 29, 2021, 5:28:42 AM11/29/21
to brython
Le mardi 23 novembre 2021 à 09:18:23 UTC+1, Olof Paulson a écrit :
TKinter or other Python GUI packages?
Being able to trigger a ’Native Python gui’ like tkinter would be an example that I think learners would appreciate.
Is there a way to run tkinter or any of the other gui Packages with Brython/Scrimba or is a JS wrapper the more likely way(less python-y for me)?
 
Porting a Python GUI such as tkinter to Brython has been suggested a few times and my answer was always "in a browser, the GUI is just HTML/CSS" - assuming that Python developers are familiar with these technologies.Your message makes me realize it's wrong, and that a Python GUI would be useful.

I have started a port of tkinter, which is probably the most popular in the Python community. It will probably take a few weeks to have something decent, but I already have a version of the Rock Paper Scissors game that works more or less the same with Brython and CPython.

Olof Paulson

unread,
Nov 30, 2021, 2:55:43 AM11/30/21
to brython
Wow, that is both awesome and at the same time I apologize for the extra work you just ..’won’
Thank you Pierre! 👍 🙏 
I really look forward to trying and creating a Tkinter tutorial on scrimba with your new port.

Again, wow on the game!
I am guessing the code you shared will work in a regular brython  session but not in Scrimba?
I.e what do I need to run your rock,Paper, Scissors version?

Looking forward to ports immensely...

Any other potential ports you see on horizon, based on same logic?

Victor Norman

unread,
Nov 30, 2021, 5:18:42 PM11/30/21
to brython
Pierre, Olaf,

First, yeah!!!  Tkinter in the browser sounds excellent!!

Second, how do I try your tkinter-based game?

Third, if you want a bunch of games to try with your tkinter port to brython, let me know. I have 50 or 100 final projects from students that used tkinter.

Vic

Ian Sparks

unread,
Dec 1, 2021, 1:55:06 PM12/1/21
to brython
I ran with the attached file (hopefully will attach):

Then in a command window:

python3 -m http.server 9000

and then browsed to:

I think it is very interesting and that python developers will be happy to have a GUI toolkit which abstracts away all the HTML. But at the same time, this code injects stylesheets into the document and uses a mix of tables and divs to style the tkinter widgets. I can see people immediately wanting to be able to control that styling...
rock_paper_scissors.html

Pierre Quentel

unread,
Dec 22, 2021, 2:57:30 AM12/22/21
to brython
I have spent most of the last two weeks of my Brython time trying to port Tkinter. It's very easy for some basic widgets (Label, Button, Radiobutton etc.) but very hard for others (implementing only a small fraction of the Text widget features was absurdly long), and I am afraid that it would take still many more weeks to cover all the Tkinter features.

Moreover, I realize that there will always be the problem of blocking functions: for instance, the functions in tkinter.messagebox are blocking in CPython and cannot be so in Brython.

I am moving to another direction: writing a Brython-specific UI module, with an API loosely inspired by Tkinter, hiding the underlying browser stuff (CSS, HTML, events etc.), but closer to the DOM APIs to be relatively easy to develop, test and maintain.

This module (currently called browser.ui) is still very unstable, I will post a new message when it starts being usable.

Victor Norman

unread,
Dec 23, 2021, 2:47:46 PM12/23/21
to brython
Pierre,

I wonder if you could look at GuiZero, which is a layer on top of Tkinter. But, I don't think it has any of those pop-up dialog boxes that you said give you trouble.

We use GuiZero now in our Intro Programming course here at Calvin University, because it is easy to install, more intuitive to use, and the documentation is better than the Tkinter documentation, which is hard to find.

Also, to try out what you've done in your port of Tkinter, do I just include these lines in my index.html?:

<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython.js"></script>
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js"></script>

I'm about to try out some of the many old Tkinter projects I have from previous years, to see if they will work with your brython Tkinter stuff.

Thanks so much for your work.

Vic

Victor Norman

unread,
Dec 24, 2021, 9:54:12 AM12/24/21
to brython
Looks like the Tkinter you had working is now broken. For the rock_paper_scissors.html file, I get this now:

brython.js:7624 Traceback (most recent call last):
  File http://localhost:8000/rock_paper_scissors.html#__main__ line 24, in <module>
    panel = Frame(root)
  File VFS.tkinter/__init__.py line 849, in __init__
    self.config(**kw)
  File VFS.tkinter/__init__.py line 343, in config
    inner=self.element.firstChild.firstChild
AttributeError: 'NoneType' object has no attribute 'firstChild'

I'm so hoping that what you had working for Tkinter can be restored. I have all these old projects written in Tkinter that I'd like to be able to showcase in the web. I don't know that any of them use tkinter.messagebox() or the other modal dialogs.

Thanks.

Vic

Pierre Quentel

unread,
Dec 25, 2021, 5:07:16 AM12/25/21
to brython
Le vendredi 24 décembre 2021 à 15:54:12 UTC+1, Victor Norman a écrit :
Looks like the Tkinter you had working is now broken. For the rock_paper_scissors.html file, I get this now:

brython.js:7624 Traceback (most recent call last):
  File http://localhost:8000/rock_paper_scissors.html#__main__ line 24, in <module>
    panel = Frame(root)
  File VFS.tkinter/__init__.py line 849, in __init__
    self.config(**kw)
  File VFS.tkinter/__init__.py line 343, in config
    inner=self.element.firstChild.firstChild
AttributeError: 'NoneType' object has no attribute 'firstChild'

I'm so hoping that what you had working for Tkinter can be restored. I have all these old projects written in Tkinter that I'd like to be able to showcase in the web. I don't know that any of them use tkinter.messagebox() or the other modal dialogs.

Thanks.

Vic


I have fixed the bug, and I have also removed tkinter from the Brython repository and created a distinct project (https://github.com/PierreQuentel/tkinter) in case other developers would want to work on it; I don't plan to maintain it myself. The instructions for use are in the README.

Victor Norman

unread,
Dec 27, 2021, 1:51:18 PM12/27/21
to brython
Pierre, et al.,

I need to implement the Canvas widget from Tkinter. I'm wondering what your process was for porting stuff. Did you just look at the source code for Tkinter and copy and paste stuff, or analyze the logic there and then recreate the logic?

I'm interested in doing the work, but just wondering if you could give me a bit of hints on the process.

Vic


From: bry...@googlegroups.com <bry...@googlegroups.com> on behalf of Pierre Quentel <pierre....@gmail.com>
Sent: Saturday, December 25, 2021 5:07 AM
To: brython <bry...@googlegroups.com>
Subject: [brython] Re: Rock, Paper Scissors - ’Game’ in Brython - Need some help
 
--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/BvTI9s9dMnQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/9b8d40e2-063c-4f1b-9f19-4545a4c777b4n%40googlegroups.com.

Pierre Quentel

unread,
Dec 27, 2021, 3:27:04 PM12/27/21
to brython
Le lundi 27 décembre 2021 à 19:51:18 UTC+1, Victor Norman a écrit :
Pierre, et al.,

I need to implement the Canvas widget from Tkinter. I'm wondering what your process was for porting stuff. Did you just look at the source code for Tkinter and copy and paste stuff, or analyze the logic there and then recreate the logic?

I'm interested in doing the work, but just wondering if you could give me a bit of hints on the process.

Vic

I didn't look at the source code (the Python code for tkinter is mostly a wrapper around code written in TCL, probably itself using C libraires ?). I tried to reproduce the behaviour observed with Tkinter widgets. For the pack geometry manager I followed the algorithm described in the TCL documentation (https://www.tcl.tk/man/tcl/TkCmd/pack.html).

Good luck !

Olof Paulson

unread,
Jan 10, 2022, 3:58:21 AM1/10/22
to brython
Thank you for trying Pierre!
I’m sorry it didn’t work as planned.

I realise use-cases will vary for different people.
In my case I wanted to create a ’course’ on how to build GUI’s so probably some ’missing features’ would be ok, as long as I could help people get a decent part of the way towards GUI-building.

I don’t know how far along the way your test would help with that or how much more would be needed, or if it’s even feasible.

I appreciate that building/adding a feature, because ’Olof would like to do a course’ isn’t necessarily a good ’open source’ approach to including features, so I won’t push ;-)

Again Thank you for trying!

Look forward to your new GUI-ideas birth!

Belated Happy new year to everyone - I wish you all a  non pandemic continuation of 2022
Reply all
Reply to author
Forward
0 new messages