简体   繁体   中英

How is Python interpreted with wxPython, PyQt, PySide or Tkinter?

I got curious and have been reading about GUI development using Python for the past hour. After reading documentation of wxPython, PyQt, Nokia's Python bindings for Qt along with Tkinter a question came to my mind.

When I create a console application with Python, it runs using the embedded Python interpreter (which I assume is usually if not always in my case cpython).

So I was wondering, what's the case with these "widget toolkits"?

  • How is the Python code executed and what interprets it (or executed it)?

  • Which part of my Python code is interpreted using the Python interpreter?

  • Or does the Python code get lexically analysed and then parsed by the widget's toolkit which then interpretes and executes (or compile during build)?

I am looking forward to understanding what goes on in the background in comparison with Python applications' (a bit simpler to understand) interpretation with the Python interpreter.

Thank you.

PS. To whichever genius thinks that this question deserves to be closed; A lot of people wonder the internals of external libraries and systems. Especially those which are not as simple as they look. There currently is not any question explaining this on SE.

This is just a really generalized high-level explanation about "GUI toolkits"...

Lets say you decide to use the Qt framework. This framework is written in C++. There are two different python bindings that can be used, allowing one to write a GUI application in python against the same API as the C++ version.

The python bindings provide a wrapping around calls into the C++ code. PyQt4 for instance uses sip , while PySide uses shiboken . These are just language wrapping tools that take specifications for how to map between the C++ objects and their intended python interface.

Ok, so you start using PyQt... All of the code you write has to pass through the python interpreter. Some of it may be pure python. Some of it will call into C++ libs to create things like your widgets. In Qt, there will be a C++ pointer associated with the python instance counterpart.

It is the C++ layer that is then communicating with the window manager of your platform, to turn platform-independent API calls into something platform specific, like how to exactly draw a button or menu.

Whether you create a console only or GUI based python application, it all goes through the python interpreter to interpret your python code. Something must interpret the python language for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM