Are there any benefits to using Python for GUI development? - user-interface

I was looking into Tkinter, but I was wondering if there are any other packages that help with GUI. Even though Java is more robust than python, python is faster to write and would be very helpful if I am just trying to create a quick application. I usually use .Swing and .awt in java to make all of my applications.
Also, Is there something similar to JWS for python? I am looking to add a link on a website that will fire up a python coded application
Thanks
(P.S. I'm using Python 3.2.2)

I love using tkinter with python. It is pretty easy to do, there are lots of examples, and numerous questions with answers on here too! Also, 90% of people with python have tkinter already on their system, making distribution pretty straight forward. I also have had success using py2exe to create windows executables.
Here is a gui that I wrote in all of ~10 minutes. Once you understand the syntax it is very easy.
And another more elaborate one that I wrote with vtk and matplotlib embedded into the gui for 3D and 2D graphics! The question I asked with this.

Yes, python and tkinter are excellent for developing GUIs. While this is true of most scripting languages, I think these two make a particularly good combination.
For most GUIs, functionality is more important than form (ie: eye candy is not top priority). Even then, it's possible to make very nice looking GUIs with Tkinter. Tk has been my go-to toolkit for close to twenty years. It is most easily used with Tcl since that is its native language, but there's no denying the advantage python has over Tcl as far as built-in functionality goes.
That being said, all of the toolkits available to a python programmer are good. Tkinter's main advantages are that it is extremely easy to use and you probably already have it installed, so the barrier for entry is very low.

Related

Is there a way to create a GUI in Lua?

I am working on a Genetic Algorithm solution to TSP in Lua, and have reached a point where I need a better method of troubleshooting and checking results. The best way to do this would be with a GUI, but I can't seem to find anything about GUIs in Lua.
I've done some searching around Google, and haven't found anything built in to the language. I have found Toolkits such as the one found here:
http://lua-users.org/wiki/GraphicalUserInterfaceToolkits
However, I am new enough to Lua that I do not know how to properly use these. Any help on the matter would be greatly appreciated.
A few ideas:
But first, what platform are you on?
Are you constrained by platform? If not, I've done very exciting things directly on an iPad, in Codea. Pure Lua, built on OpenGL, so built-in API for graphics support.
Beyond that, you could probably use Love2d. It's meant for game dev, but you could probably adapt it to your needs. It's a Lua API, has graphics support, and is cross-platform. I don't know much about it (yet), so others could pipe in with their thoughts/opinions.
If you are still shaky in Lua, I suggest to stick to the console for a while. GUI, whatever the language, is usually messy and unsatisfying for beginners.
If you already know some HTML and Javascript, consider using Lua with a web framework, and using the browser to control your program through a REST API:
Awesome-Lua#Web/Networking Platforms
Apart from that, I have yet to find a GUI framework that feels right for Lua. Almost everything is a thin wrapper around a C or C++ API and handles exactly like that. On the other hand, with the web and Electron on the rise there seems little need for it.

How can I make an GUI Application in Lua

First I'll show you an example of what I am talking about: GUI Example
I've been studying Lua for around a week now, and I'm really curious of how I would do this. Basically (for now, and learning purposes), I just want to make a GUI with 2 buttons, 1 to start the specified (.exe), and one to exit the GUI.
Is this possible? How would I go about doing this? Any information would be great!
I believe you may want to take a look:
http://lua-users.org/wiki/GraphicalUserInterfaceToolkits
If you want something well know and tested I would go to Qt, if something light: FLTK.
If you are an absolute beginner, i.e. you don't have any programming experience in other programming languages, I advice you to learn Lua very well without trying to mess with GUI programming, which is inherently much harder.
When you will have a good understanding of Lua, then go for a GUI toolkit for Lua. I use wxLua so I can only give you some hints on that.
Since it is not a "native" Lua toolkit, but it is a "binding" to a well-known cross-platform GUI library (wxWidgets) you must study both the wxLua documentation and wxWidgets manual (at least to some degree).
wxLua binary distribution comes with everything needed to use it (you don't even need a separate Lua interpreter, it has its own) and contains a good number of example applications.
The following script is a trivial approximation of what you want to do, but (I repeat myself) you should really learn the basics of Lua before attempting GUI programming.
local wx = require 'wx'
local PATH_TO_APPLICATION = [[notepad.exe]] -- Windows assumed for sake of exemplification
local ans = wx.wxMessageBox( "Should the application be started?", "Hi there!",
wx.wxOK + wx.wxCANCEL + wx.wxICON_QUESTION )
if ans == wx.wxOK then
wx.wxExecute( PATH_TO_APPLICATION )
end
To run the previous script you must be sure that wxLua is installed correctly in your interpreter search path. Otherwise you must use the wxlua.exe interpreter that comes with the distribution.
Note also that wxLua interpreter (latest wxLua stable release) runs with a version of Lua 5.1, so try not to use features of Lua 5.2 in your scripts. Basic Lua syntax and semantics is almost the same, but there are some slight differences and Lua 5.2 has a couple of added features. So be careful with your learning path.
IUP should be the easiest way to create a GUI with Lua. However you will meet a brick wall if you try to install IUP on Linux. You have to hope someone has pre-installed it or someone has pre-written an install package for your version of Linux. If you want other people to be able to run your code later it will be virtually impossible to set things up in reasonable way. That is really an error by the Lua/Iup team because I have no trouble in using Iup from the C programming language and it seems to be widely compatible with many versions of Linux. It is the opposite of the usual situation where it is very easy to set up a scripting language and difficult to set up a low level language like C.
Have you checked wxLua ? This is the only desktop gui framework I am aware of for Lua.
Another example is IUP:
http://www.tecgraf.puc-rio.br/iup/
It is supported for Microsoft Windows and Unix

Modern GUI programming in Python 3.3

I am putting together a few programs, and it's about time to start making GUI's for some of them. The code is currently written in Python 3.3.
I have researched a few GUI's for Python, namely Tkinter, wxPython and PyGTK. Everything I am finding seems to only create GUI's that look fairly archaic. I have created a couple of example GUI's, and they all work, they just look very Windows 95.
An example of what I am finding/creating:
An example of what I want-ish:
Is it simply an advanced knowledge of how the GUI's work, or are there just GUI modules more suited for "modern" looking GUI's?
If it is advanced knowledge of how the GUI's work, are there some tutorials out there for how to make GUI's look more "modern".
Thanks in advance.
Tkinter comes with a set of widgets called "themed tk", provided by the ttk module. It provides more modern-looking alternatives to some of the core widgets such as buttons and labels, and it also has a few new widgets such as a notebook and tree.
After a lot of research I've decided to use the Qt bindings library for Python called PyQt5 (http://www.riverbankcomputing.com/software/pyqt/download5). It's quite easy to implement and has tons of documentation. The interface elements (called widgets in Qt) look exactly like the ones in the host operating system: if you run the program in Windows 95, they'll look like that, same for Windows 7, and even MacOS. I find Qt extremely powerful. I'm developing a Python/MySQL application and the QtSql module helps a lot in the development with creating tables.
You can use htmlPy. So you can create GUI's with css html js with good looks.
QT is a good choice in many cases, but sometimes you need much faster response time, or native support of OpenGL(ES), or just another license. There are a lot of alternatives:
GUI Programming in Python (many specific frameworks): https://wiki.python.org/moin/GuiProgramming
The most widespread cross-platform GUIs: https://docs.python.org/2/library/othergui.html

Python 3.x website and app GUI

I am only starting out to learn programming, currently on Python 3.2, and was looking to build a few simple applications and possibly website(s), also simple. I want to know a good GUI library to start that:
is simple with good control (not a major issue, I'm planning to advance as much as possible anyway);
is cross-platform, with a native feel;
has good tutorials somewhere (please post link);
I can use to sell applications/make profit from websites with little to no licensing issues (a must);
can use Chinese characters as strings (not a must, but would definitely be a game changer).
Thanks a lot!
There are two main options for cross platform GUIs in Python 3:
Tkinter is simple and ships with Python, but applications can look a bit ugly. I like this site for learning it, although it's a bit old.
Qt is bigger and more complex, but produces powerful, good looking applications. If you want to make proprietary software with it, you'll need to use PySide, rather than PyQt, but how you use them is almost identical. There are plenty of tutorials online (mainly for PyQt, which has been around longer, but they're fine if you're using PySide).
Both should handle any characters, including Mandarin, so long as the system has fonts with those characters to display them.
Most of the tutorials for both will be based on Python 2, so you'll have to make a few changes. print "foo" becomes print("foo"), and Tkinter becomes tkinter, for example.

Favorite graphical subsystem to program in

Ok, this is an interesting question to ask because everyone has a say in it.
What is your favorite library to program in for GUI's and the language that you program it in. Give a short reason why. (ex. Gtk, Qt, Windows, etc..) Just an FYI, this includes any scripting language that you program a GUI in Python, Perl etc...
Frankly I've always done Gtk in C, but I'm starting to warm up to Qt in C++ with the new KDE. I've never been a big fan of Windows programming.
ChrisW. stated that I did not give a reason for Gtk/Qt so here goes. I started with Gtk because when I started programming GUI's I was working in Linux and there was more Gtk information available. Started utilizing Qt when I started working more in KDE but really the move to Qt was based on trying to move to C++ and learn more languages. I've never been a fan of basic Windows programming, but I do enjoy a little DirectX now and then :P
Recently I had the opportunity to work with both wxWindows and QT, while some time ago I wrote some small programs using FLTK and Gtk. My conclusion is that widget libraries tend to be very similar; each one has its strenghts and its quirks.
Instead of advocating a specific library, then, I would like to advocate the use of high level languages in GUI programming: the development cycle is way faster and GUI programs are rarely CPU bound, so the performance hit is rarely a problem.
If a GUI program has to perform some intense computations, just develop a core library in C or C++, but keep the interface in Python or whatever other interpreted language.
People like to bash Swing for being old, slow and ugly, but it's just not true. Swing is mature, is faster than ever on Java SE 6/10, looks decent enough, and is tolerable to program. Above all, I've found Java + Swing to be the most trouble-free cross-platform combination. It also works remarkably seamlessly with Jython (Python on JVM).
SWT could also be an option, but so far I've been happy with Swing.
I realise you're focusing on application GUIs but if you want a quick, powerful and fun way to visualize anything on your computer, you can't go past Processing
From the site:
Processing is an open source
programming language and environment
for people who want to program images,
animation, and interactions. It is
used by students, artists, designers,
researchers, and hobbyists for
learning, prototyping, and production.
It is created to teach fundamentals of
computer programming within a visual
context and to serve as a software
sketchbook and professional production
tool. Processing is an alternative to
proprietary software tools in the same
domain.
WPF in particular, and XAML in all its reincarnations (WPF, Silverlight, Moonlight).
C# on top of .Net 3.5/Mono: $0
Visual Studio Express/MonoDevelop: $0
Being able to tell the designer "make my program pretty" and continue coding features: priceless.
I liked writing to video memory under DOS: for an animated game (i.e. an Asteroids clone), that was as fast (performant) as I knew how to do it (certainly faster that using the BIOS API).
This is really a somewhat subjective question, so there is no best or correct answer to it. The following is based on my (limited) experience:
I personally like wxWidgets with PLT Scheme for writing simple but flexible GUIs. There are much more advanced toolkits, but I usually do not need their features. wxWidgets is flexible and the Scheme interface follows Scheme traditions of being powerful with a relatively simple structure. I like the fact that wxWidgets is portable, and yet tries not to actually draw its own widgets, but can use native or common toolkits of the environment it is used under. It is written in C++ but I never used its C++ interface.
That is not to say that in my opinion Scheme will generally be the optimal language to write your application in. In fact there are many kinds of applications I would not write in Scheme, even though I like the language. But regarding the GUI programming part, that is my favourite because of its straight-forwardness, and the way that a functional language like Scheme goes well with declarative-style GUI programming.
Of course you will not have the same level of control when using that as when having your program involved in every stage of the window construction and input reaction, by using an event loop (such as with Win32API or Xt/Intrinsics). But that is not always convenient and often unnecessary, and seems to become decreasingly common.
Note: The wxWindows toolkit was renamed wxWidgets, but my installation of a rather recent version of PLT Scheme still comes with the older wxWindows. I am not sure whether there is an updated package of wxWidgets available or if it is going to be included in a future version of PLT Scheme.
Qt4 without question for me. Now that it has an LGPL license it makes sense for all kinds of applications that previously weren't possible. Additionally, it changes C++ in ways that dramatically improve the experience of using the language. (Things like a foreach and forever loop, atomic operations on integers, and memory management)
Gtk and is the primary window-drawing graphical subsystem I have experience working with (and is therefore my favorite XD).
As far as general graphics subsystems go, however, OpenGL (typically in combination with GLUT) has been an easy and productive ride for me. Regrettably I have little DirectX experience to compare to, though :S
For writing souped-up versions of standard Windows components, I loved Borland's VCL, and am very pleased with .NET.

Resources