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 the PySide and now 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 widely followed when importing modules in Python. First, is to use a direct import <module> statement. This statement will import the module and create a reference to the module in the current namespace. If you have to refer to things (functions and data) that are defined in module, you can use module.function. Second, is to use from module import *. This statement will import the module and create references in the current namespace to all public objects defined by that module. In this case, if you have to refer to things that are defined in module, you can simply use function.

Therefore, in order to use the 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 like PySide.<function_name>. In the latter, you can simply call the function by <function_name>. Also, 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 prefer to use the latter format except that instead of importing all the modules by *, the specific modules are imported by their names. This is done to avoid allocating memory for the modules that we don't use.

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

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