Importing PySide objects

Congratulations on setting up Pyside successfully on your system. Now, it's time to do some real work using PySide. We have set up PySide and now we want to use it in our application. To do this, you have to import the PySide modules in your program to access the PySide data and functions. Here, let's learn some basics of importing modules in your Python program.

There are basically two ways that are widely followed when importing modules in Python. The first is to use a direct import <module> statement. This statement will import the module and creates a reference to the module in the current namespace. If you have to refer to entities (functions and data) that are defined in module, you can use module.function. The second is to use from module import*. This statement will import all of the entities that the module provides and set up references in the current namespace to all the public objects defined by that module. In this case, referencing an object within the module will boil down to simply stating its literal name in code.

Therefore, in order to use PySide functions and data in your program, you have to import it by saying either import PySide or from PySide import*. In the former case, if you have to refer to some function from PySide you have to prefix it with PySide, such as PySide.<function_name>. In the latter, you can simply call the function by <function_name>. Also, please note that in the latter statement, * can be replaced by specific functions or objects. The use of * denotes that we are trying to import all the available functions from that module. Throughout this book, I would prefer to use the latter format as I do not have to prefix the module name every time when I have to refer to something inside that module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.120.136