Am I Crazy to Port Tkinter to Brython?

963 views
Skip to first unread message

Christopher Forgeron

unread,
Jan 7, 2015, 7:49:02 AM1/7/15
to bry...@googlegroups.com
Hi all,
 
 Long time lurker, first time poster.

 The subject says it all. I hate duplicating work, or wasting my time on something that is a dead end. I've done my research, and I can't seem to find a Tcl/Tk JavaScript port, nor can I find a full UI for Brython, so I'm asking for opinion.

 I see CodeSkulptor has ported the python package simplegui to it's site, and from the chatter on this group, I believe it's a javascript lib, but there may be license issues with it's reuse.

 I would need a fairly full GUI for a web app, one that is licensed BSD/Python, not GPL.


 I've already managed to port enough of tkinter last night that this simple tkinter intro script runs in Brython:


            import tkinter

            def stopProg(e):
              root.destroy()

            root = tkinter.Tk()
            print("attempting Button")
            button1=tkinter.Button(root, text="Hello World click to close")
            button1.pack()
            button1.bind('<Button-1>',stopProg)

            root.mainloop()

 I reference the code in _tkinter.c to ensure I'm making a compatible port. That was a great way to get my feet wet with my first Brython experience, but I want to pause and see what others think.

Some Background:

I haven't worked with Tkinter before. When I've needed to make a Python desktop GUI in the past, I went with Qt, as I have experience with Qt from C programming days.

My last big JavaScript UI was with Dojo Toolkit, so I have a fair amount of experience there, and I must say Dojo is a great option if you're in the JavaScript world. AMD modules make it worth the price of admission, but the price of admission is oh so high.. much of the learning is through hard work.

My current requirements at work have me dusting off a Dojo prototype, and developing it into a full product - And I'm going to spend a few days checking if it could be viable to do this in Brython instead.

I  have a desire to stay inside of Python as much as possible, particularly after my last experience. The last few weeks found me porting an old hacky, massive Unix C prog to Windows. While I've been programming C since the 80's, I haven't had need to do much C for the last 4 years as I've been purely Python. Getting back into C after years of Python reminded me how much time is wasted dealing with language and compiler cruft, rather than developing the application.

Javascript is better then C, but still has a lot of issues, and by all means, scales into a ugly mess by the time you've created a complex app. I want real classes and inheritance, and in general the syntax of Python.

I have considered wrapping Dojo for Brython, but Dojo is a full framework that wraps it's Widgets (called Dijits in Dojo). With Brython, I wouldn't need the Dojo framework.

Brython does poke along a bit slower than I like, but I view that as a temporary problem, one that I may be able to help with if I'm in Brython regularly for my webgui work. Dojo is not a speedy framework either, so I'm not giving up a lot by switching.

So: Since Tkinter seems to be the ugly child of Python, I looked at wxPython, and Qt - Both would have license issues with a port I feel, not to mention that they are quite large, even if only a subset is ported. Perhaps I'm wrokn? I keep coming back to Tkinter as the best choice for GUI porting.

Tkinter has the advantage of being the default GUI for Windows Python, so porting it to Brython means that some/most of the Tkinter apps in Python would then port to Brython easily - I think that's a worthy goal. I also think that there must be some pythonic logic for Tkinter that I'm just not seeing - Or perhaps was it the easiest way to gain some cross platform UI ability?

Additionally, a compatible Brython Tkinter module  would make it easy to develop an application locally in Tkinter, offline with the full support of an IDE / Debugger to step through Python logic issues. Staying inside of a local IDE does give you speed advantages as opposed to working in a browser.

Tk is the graphic layer that sits on top of Tcl. Tcl is it's own scripting language by itself, and I have no interests in porting a full Tcl reference as well. This is one area where my lack of experience with Tkinter makes me unsure - Will I need most of Tcl to make this work?  

My plan would be that my Tkinter port would be calling to Javascript directly for it's graphic primitives (HTML5 as much as I can), and this wouldn't need TCL. This should keep complexity down, and keep UI speed up. While I want to remain in Brython as much as possible, I have little problem with optimizing libraries in a different language - All of Python's speed intensive modules are written in C. I want my application to be Python, the libs can be whatever as long as I have Python compatibility. 

I would then port/wrap a few key widgets, like GridX, as that's beyond my desire to recreate from scratch - Possibly pull in any license-compatible JQuery bits that would flesh out the UI. I do have to get back to productive commercial output relatively fast, so this all works if there is an overall savings of time for my project due to being in Python not Dojo, otherwise I should be coding in Dojo right now.

I think that's plenty for a first message, and you can see I've put some thought into this - I await your posts of "here's the URL to the exact library you described". :-)


Thanks for your comments.

Kiko

unread,
Jan 7, 2015, 8:41:52 AM1/7/15
to bry...@googlegroups.com
2015-01-07 13:49 GMT+01:00 Christopher Forgeron <csfor...@gmail.com>:
Hi all,
 
 Long time lurker, first time poster.

Welcome.
 

 The subject says it all. I hate duplicating work, or wasting my time on something that is a dead end. I've done my research, and I can't seem to find a Tcl/Tk JavaScript port, nor can I find a full UI for Brython, so I'm asking for opinion.

I also hate duplicating work :-) 

I think that's plenty for a first message, and you can see I've put some thought into this - I await your posts of "here's the URL to the exact library you described". :-)

Here's the URL to the exact library you described: http://jqueryui.com/ 
:-P

No, i'm joking (or not?).

A web page is not exactly similar to a desktop application and in some way modern desktop applications are using richer web pieces (IPython console vs notebook as a successful example) so:

Why use an old piece of crap (Tk) and port it to the browser when you can use some modern frameworks like jqueryUI or others? (honest question and I'm opinionated about Tk, pyqt user here)

A brythonic wrapper around a modern js lib has more sense for brython (Python in the browser)?


Thanks for your comments.


Thank you for opening the conversation.

Billy Earney

unread,
Jan 7, 2015, 8:51:41 AM1/7/15
to bry...@googlegroups.com
I agree with some of Kiko's comments, but if many python programs that use Tk can be easily migrated to the web via brython via a Tk port, I think it is worth a shot!  I believe some components will be easier than others.  I tried porting Turtle Graphics (which uses Tk) to brython, but had to take out (and rewrite) many of the parts that rely on the Tk canvas.  Hopefully most of the other components are more compatible with their corresponding web components.

One of my side projects is to translate pygrame to brython.  Much of the code is taken directly from the pygame project, but some components have to be rewritten.   I believe porting these libraries can save quite a bit of work, and can bring many existing projects to the web.  For many dying projects, these efforts can breathe some fresh air into them.

Maybe I'm over optimistic, I don't know. :)

Billy

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/CAB-sx63pkZpq_ReT_LA1mnE98witGw2L%2BTR6VtFMhzCGA%3Dc%2BUg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Kiko

unread,
Jan 7, 2015, 9:09:57 AM1/7/15
to bry...@googlegroups.com
2015-01-07 14:51 GMT+01:00 Billy Earney <billy....@gmail.com>:
I agree with some of Kiko's comments, but if many python programs that use Tk can be easily migrated to the web via brython via a Tk port, I think it is worth a shot!  I believe some components will be easier than others.  I tried porting Turtle Graphics (which uses Tk) to brython, but had to take out (and rewrite) many of the parts that rely on the Tk canvas.  Hopefully most of the other components are more compatible with their corresponding web components.

Tkinter/TK has changed the API from py2 to py3 so maybe the number of TK apps in python3 is not so big. I think that the number of users of PyQT, wxPython, pyGTK (pygoobject now?), kivy is infinitely higher than the number of apps made with Tk in Python3 (I don't have any statistic so I'm inventing this data).
 

One of my side projects is to translate pygrame to brython.  Much of the code is taken directly from the pygame project, but some components have to be rewritten.   I believe porting these libraries can save quite a bit of work, and can bring many existing projects to the web.  For many dying projects, these efforts can breathe some fresh air into them.

In this case I think PyGame is the first citizen lib in the python gaming world and I think it can has more sense this port.
 

Juan Carlos

unread,
Jan 7, 2015, 9:10:44 AM1/7/15
to bry...@googlegroups.com

For more options, visit https://groups.google.com/d/optout.


Why not to use Bootstrap 3, it even has Bootstrap-Material which is a port of Material Design to Bootstrap.

Kiko

unread,
Jan 7, 2015, 9:41:11 AM1/7/15
to bry...@googlegroups.com

 

 The subject says it all. I hate duplicating work, or wasting my time on something that is a dead end. I've done my research, and I can't seem to find a Tcl/Tk JavaScript port, nor can I find a full UI for Brython, so I'm asking for opinion.

I also hate duplicating work :-) 


Maybe this could be a way to go or a good start:

Billy Earney

unread,
Jan 7, 2015, 9:50:24 AM1/7/15
to bry...@googlegroups.com
We probably do need some experience in emscripten.  I definitely see emscripten being a benefit porting some c libraries for use with brython.  Looking at emscripten-qt maybe a good thing.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Christopher Forgeron

unread,
Jan 7, 2015, 9:58:41 AM1/7/15
to bry...@googlegroups.com
Hey, thanks for the input.

Many points, let's discuss a few:

1) jQuery: Yup, I should really think long and hard about not just using a jQuery UI lib. The reason I chose Dojo vs jQuery a year ago was because Dojo provided a framework for other aspects of coding. If I use Brython as my source of classes/modularity, then I no longer need Dojo, and jQuery pops back up as a possibility.

2) PyGame - I've seen some of this, and perhaps it was some of your work Billy - I've got moderate interest in that, since it now supports Python3. My main focus is boring business UI for now, but I'd like to code some fun in the near future - Perhaps we should chat about how far you got with your Tkinter work, and where you're going with a PyGame port. It's LGPL, not sure if that will cause issues for me - At first thought it should be okay. 

3) Why is Tkinter an old piece of crap? I see this often, but it's not qualified. If I do go through with this port, then I will learn myself what the pros and cons of Tkinter are. I do agree it's not the popular choice, thus me calling it the 'Ugly Stepchild'. C is an even older piece of crap, and we pour tons of effort into it each year.  It seems to be very modular, which lends itself to being the building blocks for a simple or a complex UI it you like. 

4) Online / Offline ability - This could happen with PyGame, or something similar that exists offline as well, but I do believe this is a valuable plus that jQuery won't give me. 

5) Small. Tkinter isn't big. PyGame / Qt / etc are. I don't foresee them ever being able to be distributed with Brython, which is something that would go a long way to making Brython more Python compatible. 


Still thinking out loud here, and welcoming the feedback. 

Juan Carlos

unread,
Jan 7, 2015, 10:15:06 AM1/7/15
to bry...@googlegroups.com
The complicated part is making all work the same on all browsers and OS including mobile and IE, thats something JQueryUI and Bootstrap do good, trust me that can take A LOT more than doing the actual thing. 

I think PyGame is already working on Browser, thats what Pilas Engine on browser uses ?

Offline/Online should be agnostic of UI.

Billy Earney

unread,
Jan 7, 2015, 10:22:14 AM1/7/15
to bry...@googlegroups.com
Pilas Engine as in http://pilas-engine.com.ar/  ?    I don't understand the language.  Does anyone know what language that is in?   is there an english version?

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Christopher Forgeron

unread,
Jan 7, 2015, 10:46:26 AM1/7/15
to bry...@googlegroups.com


On Wednesday, 7 January 2015 11:22:14 UTC-4, Billy Earney wrote:
Pilas Engine as in http://pilas-engine.com.ar/  ?    I don't understand the language.  Does anyone know what language that is in?   is there an english version?

Spanish, I assume as it's in Argentina. Google can do a good job translating if you want to pick though it.

This is one of the reasons I believe it's good for my documentation to be written in 'Simple English' a subset of standard English, to allow auto-translators to work better. We keep forgetting about all of the good code in the rest of the world (Brython is a great example, being primarily French)


Juan:

 Yes, the browser compatibility thing is big - I've had lots of fun with that back in the day of IE4 / Netscape. :-) It's better now, but we also demand more from our browsers, and little things like being off bu a pixel are more of an issue than they were in the Netscape days.  It's a vote for wrapping an existing JavaScript UI, or at least it's primitives. 

Juan Carlos

unread,
Jan 7, 2015, 10:55:37 AM1/7/15
to bry...@googlegroups.com
On Wed, Jan 7, 2015 at 12:46 PM, Christopher Forgeron <csfor...@gmail.com> wrote:


On Wednesday, 7 January 2015 11:22:14 UTC-4, Billy Earney wrote:
Pilas Engine as in http://pilas-engine.com.ar/  ?    I don't understand the language.  Does anyone know what language that is in?   is there an english version?

Spanish, I assume as it's in Argentina. Google can do a good job translating if you want to pick though it.

This is one of the reasons I believe it's good for my documentation to be written in 'Simple English' a subset of standard English, to allow auto-translators to work better. We keep forgetting about all of the good code in the rest of the world (Brython is a great example, being primarily French)

Spanish.
Argentina.
Its a team from here, hehe, I speak Spanish.

Write on simple English is actually a best practice for real, I can traduce you Spanish if needed, but I know its a WIP to move Pilas to English...

Kiko

unread,
Jan 7, 2015, 11:22:40 AM1/7/15
to bry...@googlegroups.com
2015-01-07 16:54 GMT+01:00 Juan Carlos <juancar...@gmail.com>:
On Wed, Jan 7, 2015 at 12:46 PM, Christopher Forgeron <csfor...@gmail.com> wrote:


On Wednesday, 7 January 2015 11:22:14 UTC-4, Billy Earney wrote:
Pilas Engine as in http://pilas-engine.com.ar/  ?    I don't understand the language.  Does anyone know what language that is in?   is there an english version?

Spanish, I assume as it's in Argentina. Google can do a good job translating if you want to pick though it.


It is spanish from Argentina. The creator is an Argenitinian guy and there is also a community of committers in Spain. In the latest PyConES there was a workshop about Pilas.

Pilas is not based on PyGame and is a game platform used to teach programming to kids in spanish doing videogames. Classes, methods and attributes are in spanish to help native spanish spoken kids in the programming learning.

There is an experinment to use pilas in the browser but I don't know the internals. It is already referenced in the github wiki:
Maybe we could contact with tthe author to see if there are some interest to join efforts.

Pierre Quentel

unread,
Jan 7, 2015, 2:47:17 PM1/7/15
to bry...@googlegroups.com


Le mercredi 7 janvier 2015 13:49:02 UTC+1, Christopher Forgeron a écrit :
Hi all,
 
 Long time lurker, first time poster.
Welcome !

In my opinion, the short answer to your initial question is : yes !

I have been programming in Tkinter for years - in fact for the development of Brython I use a home-made text editor that I wrote in Tkinter. It will be extremely difficult to port it in Brython, for instance the Text widget has so many options that it's going to be a nightmare to support them with the same rendering in all the browsers supported by Brython. Moreover, I agree with Kiko, Tkinter is handy because it is shipped with Python, but it's not considered the best UI tool for Python.

For the moment, the best way to have a good-looking UI is to use one of the existing Javascript library. It's very easy to interact with them, for instance with jQuery UI the basic dialog demo is just

from browser import window

jq = window.jQuery.noConflict(True)
jq("#dialog").dialog()

But if you want to start an ambitious project, the best thing to do would be to write a new UI library in full Python. It would be a great way to illustrate the idea behind Brython : replace Javascript by Brython for web client programming. Billy has developed the Lib/ui package, it uses the jQueryUI CSS sheets but for the rest it's pure Python. There are a few demos in the gallery. I suggest you take a look at it and see if you could extend it with new widgets
 

Joao S. O. Bueno

unread,
Jan 7, 2015, 2:52:48 PM1/7/15
to bry...@googlegroups.com
>> Thanks for your comments.
>
>
> In my opinion, the short answer to your initial question is : yes !

I for one also think it would be fantastic to have a compliant Tkinter
implementation
in Brython -

It is easier and simpler to use than most javascript toolkit frameworks.
And as for the appearance, it logically will be CSS-temable, so there
is no problem there.

js
-><-

Kiko

unread,
Jan 7, 2015, 2:58:15 PM1/7/15
to bry...@googlegroups.com
I'm ok with the idea but I would prefer a wrapper mimicking the python syntax but using an already existing solution (e.g., jqueryUI) and not starting from zero.
 

  js
 -><-

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Juan Carlos

unread,
Jan 7, 2015, 3:43:14 PM1/7/15
to bry...@googlegroups.com
On Wed, Jan 7, 2015 at 4:58 PM, Kiko <kikoco...@gmail.com> wrote:


2015-01-07 20:52 GMT+01:00 Joao S. O. Bueno <gwi...@gmail.com>:
>> Thanks for your comments.
>
>
> In my opinion, the short answer to your initial question is : yes !

I for one also think it would be fantastic to have a compliant Tkinter
implementation
in Brython -

It is easier and simpler to use than most javascript toolkit frameworks.
And as for the appearance, it logically will be CSS-temable, so there
is no problem there.

I'm ok with the idea but I would prefer a wrapper mimicking the python syntax but using an already existing solution (e.g., jqueryUI) and not starting from zero.


If I where to do such thing I will go for implementing/porting/adapting the Zebra to Brython, 

including its ability to convert JSON-to-UI, because its all a <canvas> its exactly the same on all browsers, Android, Mobile and IE, and its on GitHub.



If I where to go for PyGame, instead I will try to implementing/porting/adapting the BGE of Blender to Brython,

including its ability to do one of the best 3D on Python, runs on all platforms, uses Python3 and OpenGL3, and its open source, just like Blend4Web does.



One can dream :)

Christopher Forgeron

unread,
Jan 7, 2015, 7:56:39 PM1/7/15
to bry...@googlegroups.com


If I where to do such thing I will go for implementing/porting/adapting the Zebra to Brython, 


Zebra does look interesting, I think I will give it a spin tomorrow.

I'm looking at Tkinter's setvar/getvar syntax, and it's interesting that you can set a watcher on a variable, so when the var changes, the widget displaying that var will update - Interesting, but I'm not sure if that's an efficient way to proceed.  

Juan Carlos

unread,
Jan 7, 2015, 9:47:29 PM1/7/15
to bry...@googlegroups.com
On Wed, Jan 7, 2015 at 9:56 PM, Christopher Forgeron <csfor...@gmail.com> wrote:


If I where to do such thing I will go for implementing/porting/adapting the Zebra to Brython, 


Zebra does look interesting, I think I will give it a spin tomorrow.

Yep, a <canvas>  draws equally pixel perfect on all browsers and platforms, dont even need CSS, but supports it.

Christopher Forgeron

unread,
Jan 8, 2015, 7:52:55 AM1/8/15
to bry...@googlegroups.com
Yup, starting to get excited  - This was what I was looking for a few years ago, but I could not find it. I'll be deploying my first test widgets late today, and I'll see what I can learn about it's suitability. HTML5 is already a required target for my app, with good browser support if you run a recent browser. Anything to distance myself from the differences in a browser will make my day easier.

I expect I will soon learn this as I comb through the Brython documentation, but I expect you can't directly script JavaScript inside of Brython? i.e:

def mostly_python():
   do_python()
   do_more_python()
   #$document[12].object.storage=string.length

The proper way would be to call a javascript function with that line in it, correct? 

Nicolas Pinault

unread,
Jan 8, 2015, 3:40:38 PM1/8/15
to bry...@googlegroups.com
Synology DSM 5.x is impressive. Looks like you are on a desktop GUI.
Does anyone knows how it is made ?

Nicolas

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Igor dos Santos Montagner

unread,
Feb 6, 2015, 6:57:24 AM2/6/15
to bry...@googlegroups.com
I also started doing a simple implementation of tkinter and already got some simple results[1][2]. I know that currently the visuals are quite ugly, but this can be solved with CSS.

My implementation is very partial right now, but I will upload it to github on the next days so other people can use it too (and contribute to it, perhaps). Most code went into making the Grid Layout work, but there are also some widgets implemented (Labels and Buttons with text variables).

[1] https://dl.dropboxusercontent.com/u/52673162/text-variable.html
[2] https://dl.dropboxusercontent.com/u/52673162/demo1.html

Stu.Axon

unread,
Feb 13, 2015, 6:48:43 AM2/13/15
to bry...@googlegroups.com
If this can ever run IDLE it would he awesome.

Nicolas Pinault

unread,
Apr 12, 2015, 4:33:57 PM4/12/15
to bry...@googlegroups.com
Hi,


Le 08/01/2015 01:56, Christopher Forgeron a écrit :


If I where to do such thing I will go for implementing/porting/adapting the Zebra to Brython, 


Zebra does look interesting, I think I will give it a spin tomorrow.
Have you made a wrapper for zebra ?

Nicolas

I'm looking at Tkinter's setvar/getvar syntax, and it's interesting that you can set a watcher on a variable, so when the var changes, the widget displaying that var will update - Interesting, but I'm not sure if that's an efficient way to proceed.  
--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Nicolas Pinault

unread,
Sep 13, 2015, 4:45:09 PM9/13/15
to bry...@googlegroups.com
Any progress on this ?
--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages