I have developed an application in C which works on command line interface. I want to make my code display data over GUI, and I would also want to provide a window waiting for user input.
I need some directions on how to proceed. I came across a few sites saying libraries in python will serve the purpose.: WxPython, TKinter, PyQt
How to start abt? How do I link my C application to the GUI? And should I develop a GUI application, too, and then link it to my C application?
I am a beginner. Please help.
Thanks.
I recommend using GTK+ or Qt for your application.
They are popular, cross-platform and both have extensive documentation and great community.
Take a look at Cython for easily connecting the C world with the Python world if you decide to link your C code with the UI, it's highly convenient as a glue language.
Depending on your application, it might be a good option to keep it as a command line application that you call from a python program. The subprocess module is the usual route here, but there are some tools that can help even more -- like commandwrapper.
As for the GUI, apart from the already mentioned (perfectly viable) alternatives in other answers, Kivy is an interesting newcomer, and pyFLTK is a lightweight, easy-to-learn, old-school approach. These are a bit exotic, but it's good to know they exist.
Finally, QT5 was recently released and it shows a lot of promise. You might want to consider it if you don't mind writing C++, it's various language wrappers are not ready yet.
You'll need to install the libraries for whichever GUI framework you want to use. WxWidgets is available for C, as well as Python, so you don't really need to link to the Python library. Other options (as indicated by Intelis) are GTK+ and QT.
If you're developing in Windows, then you may also use the Windows API to create your GUI application. Alternatively, you might consider using C++ (Either managed C++ or MFC).
Once you have installed the appropriate libraries, you will need to include them in your C source by using the #include <...> directive.
Take a look at these sites:
WxWidgets Tutorial.
GTK+ Tutorials
QT Tutorial
Related
So, I have been wanting to make my own GUI library for Python 3. And I couldn't find anything anywhere on where to start. So I decided to ask the question here.
Goal:
Be able to make Python Libraries without using other libraries.
Edit:
So, If I was to make a Library in C for Python. How would I go about doing that.
Tkinter is a python wrapper around tcl/tk's GUI toolkit , similar to how PySide/PyQt and wxPython are wrappers around the Qt and Wx C++ GUI toolkits.
If you wanted to build your own from scratch you would have to make use of existing operating system APIs and/or use something cross platform like OpenGL. For a good example of the latter you can look into Kivy, which is built on OpenGL
Different operating systems have different API's for doing GUI's. So how you have to do it very much depends on the operating system. I think one of the reasons that Python uses Tkinter is because it was already ported to different operating systems.
GUI API's are typically provided as shared libraries, often written in or compatible with C.
If you want to use those from Python, you will have to write a Python wrapper for them. For example using ctypes. Doing that requires a significant understanding of (1) Python, (2) ctypes and (3) the GUI API in question. If more than one of these technologies is new to you, I would not recommend taking on such a project.
I googled and search stackoverflow before asking this question
Answers that I don't expect:
wxWidgets is the best Python GUIUse TkInter (BIM) for GUI development.
Q. How to make a GUI without using any module/library? i.e make a GUI from scratch. Modules like tkinter not allowed.
I've made several GUIs from scratch using SDL which is a low level drawing library. The advantage of doing that is that it will look exactly the same on any platform down to the pixel and you can get it to work on embedded systems. Full screen GUIs are really easy too. Disadvantages are that it is a lot of work.
In python the pygame library wraps SDL so you would use that, and in fact that is how I made the GUI for a lab instrument which had a large colour LCD screen. The controller ran linux, but not X-windows.
pygame is an extra library, yes, but I can't think of a way of making a GUI with only what python provides.
The easiest GUI to make without "module/library" is a web-based one. I.e. generate HTML with Javascript from your Python code, and let the Javascript interact via AJAX with your Python app. This can be implemented without too much effort with just the standard Python library (and some JS code, of course), or with modules that don't require "heavy" installation of platform-specific extensions.
Features needed:
A framework, allowing me to build tab-based application with custom design (like in Hotot twitter client), keeping the native os window frame.
Compatible with Python.
My application will be running under Win/OsX/Linux/.
No Flash/Flex/AIR.
I also would like to ask if PySide does meet my requirements and is it worse or better than wxPython and Tkinter mentioned already?
Use Tkinter. It works on every platform that Python supports, is relatively easy to program in, looks pretty good on most platforms, and has the features you want. It's also built-in for most versions of Python, so your users (in many cases) will not have to install any external dependencies.
I find that Tkinter looks best on Mac OSX and Windows, and slightly outdated on some Gnome desktops. The most important feature, however, is that the API is extremely clean and easy to use and it is very lightweight. PyQt has a similar feature set, but, in my experience, its performance is significantly degraded when compared to Tkinter.
PySide is Nokia's Qt binding for Python. I'm not aware of what the differences are between it and PyQt. Ultimately, most GUI toolkits for Python are going to be cross platform and support the functionality you need. I suggest Tkinter because I feel it is the easiest and most pleasurable way to program GUI applications in Python.
I am the author of Hotot.
according to your requirements, the key for you to choose a framework is the UI framework should be able to access webview conveniently.
Hotot has several wrappers for different platforms. On Linux, we have both Qt and GTK version, on Windows, we provide a Qt version, on Mac, we have a Cocoa version, and of course we have a Chrome version. In a word, all they can easily access webkit.
PS: XULRunner is another good choice for native appearance.
Additionally to the advices given by other people, I suggest you to use PyQt which is a Python binding to Qt framework. It's widely used, cross-platform and feature-full.
Take a look at wxPython (based on wxWidgets). If you want to make it web-based, look into using Django.
Well, you mentioned PyHotOt, and it says (on its web site) that it uses pywebkitgtk, and PyGTK. PyGTK/PyWebKitGTK exists for windows. Did you check it out? I think OS X would be the weak link on GTK, but maybe it's pretty good too.
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), what is there so special(glade is GUI builder)?
Can anyone make some "personal opinion" about this choices?
I have python code, I need to make simple GUI(2 button's-open-close-read-write,and some "print" work) and then make some .exe file (is there best choice py2exe=?). Is there a lot of changes in code to make GUI?
Many thanks
If your GUI is really that simple, you should go with the built-in tkinter.
There's a Hello, Tkinter tutorial that you can follow, it's pretty straightforward. Concerning the creation of executables, py2exe should work without problems in most cases (though I haven't tried with tkinter). Another way to create an executable is to add a special parameter to your "setup.py" file:
setup(...,
entry_points = {"gui_scripts" : ['name-of-executable = name_of_package.launcher:main']})
This would, for example, create an executable that can be run by typing "name-of-executable" into a terminal (even on Windows if Python's "scripts" path is in the PATH ^^). It runs the function "main" in the module called "name_of_package". That way, you don't have to use py2exe but can create a Windows installer, or a Debian package, for instance.
For more complex projects, I can absolutely recommend PyGTK with Glade as interface designer. It requires several Python packages to be installed, plus a GTK+ installation (which is not always that easy on Windows). The API is awesome, well-documented and Glade is very easy to use, once you get used to the layouting concepts of GTK. But my opinion is kind of biased because I've done multiple projects in PyGTK. wxWidgets or PyQT are good alternatives. For example, bazaar explorer is written using QT.
I really like PyQt bindings for Qt library.
What is PyQt?
Qt itself is a very nice framework - rich, powerfull, elegant (for my taste, at least). And PyQt does a very nice job of exposing that functionality to a scripting environment.
Plus, there is a very nice book about PyQt development - Rapid GUI Programming with Python and Qt - working through it helped me a lot.
I've been using WxPython and I've tried Tk, but it seems that, while both are good and I'll likely use them for other projects, neither of those appear to be capable of accomplishing the things that I want for my current project (which is fine, they're good at what they do).
Basically what I'm looking for is something that will allow me to make rich graphical GUIs. My specific goal is a window that will draw bitmap buttons, resize the parent window automatically to fit them, and possibly animate the resize with a slide effect and have the buttons fade in. Also being able to have my own window border style instead of the inbuilt one is important to me.
This particular project will be Windows only, so non-portable libraries are fine in this case, though portable ones would be great too.
If I missed how this can be done in either WxPython or Tk, I'm all ears.
PySide: http://www.pyside.org/
The PySide project provides
LGPL-licensed Python bindings for the
Qt cross-platform application and UI
framework. PySide Qt bindings allow
both free open source and proprietary
software development and ultimately
aim to support all of the platforms as
Qt itself.
The Windows version of PySide is quite new and may be considered as a beta version. PySide is API compatible with PyQt.
How about PyQt?
http://www.riverbankcomputing.co.uk/software/pyqt/intro
Just sharing my opinion: Kivy.
Innovative open-source library. Supports both 2.x and 3.x versions of Python.
Kivy - Open source Python library for rapid development of applications
that make use of innovative user interfaces, such as multi-touch apps.
Kivy is based on OpenGL ES 2 and includes native multi-touch for each platform and Android/iOS. It’s an event-driven framework based around a main loop, and is thus also suitable for game development.
Try Pyglet. Its a library for python that makes using OpenGL very easy. You can draw pretty good 2d interfaces using Quads.
I can't tell you what is best because that is subjective but I can give you another option: PyGTK
PyGTK lets you to easily create programs with a graphical user interface using the Python programming language. The underlying GTK+ library provides all kind of visual elements and utilities for it and, if needed, you can develop full featured applications for the GNOME Desktop.
PyGTK applications are truly multiplatform and they're able to run, unmodified, on Linux, Windows, MacOS X and other platforms.