Wednesday, November 18, 2015

What is Tkinter?

        Tkinter is a Python binding to Tk GUI (Graphical User Interface) toolkit. It is the most common choice for creating gui in Python but it is not the only toolkit available. Some of this are WxPython, PyQt4, PySide and many more. Due to the fact that Tkinter comes along with every packages of Python we don't need to install anything like those of other toolkits I have mention. And it is quite easy to use and to get comfortable with in my experience using it.

Source code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/usr/bin/env python3
#
# samplewindow.py
# Author: Jesus Vedasto Olazo

"""
An example of creating a simple 
window using tkinter.
"""

from tkinter import Tk

root = Tk()
root.mainloop()

Preview:


Friday, January 30, 2015

Create Your Own Module

Example of a simple module.

Source Code - Module: example14.py

Source Code - Main Application: example15.py

Output: Python Shell

Wednesday, January 28, 2015

Module

A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitrarily named attributes that you can bind and reference.

One of the example of a module is tkinter module. The tkinter module is a tool for creating gui programs in python.

Source Code: example12.py
Output: Python Shell - GUI
 Reference: www.tutorialspoint.com

Defining Function

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.

As you may have known, Python already provide you a wide variety of built-in function such as print() and input(). But you yourself can create/define a function to use in your programs. This is called user-defined-funtion.

Source Code: example11.py
Output: Python Shell
Reference: www.tutorialspoint.com

Python Dictionary

A dictionary is mutable and is another container type that can store any number of Python objects, including other container types. Dictionaries consist of pairs (called items) of keys and their corresponding values.

Source Code: example10.py
Output: Python Shell
 Reference: www.tutorialspoint.com

Tuple

A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The only difference is that tuples can't be changed i.e., tuples are immutable and tuples use parentheses and lists use square brackets.

Source Code: example9.py
Output: Python Shell
 Reference: www.tutorialspoint.com

Python Lists

The list is a most versatile data type available in Python which can be written as a list of comma-separated values (items) between square brackets. Good thing about a list is that items in a list need not all have the same type.

Source Code: example8.py
Output: Python Shell
 Reference: www.tutorialspoint.com