60
           Pycon India 2009,IISc GUI Using Python – PyGTK and Glade A. Jai Sathish Kumar                                     S.Rajeswari [email protected]      [email protected]   

GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

Embed Size (px)

Citation preview

Page 1: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

          Pycon India 2009,IISc

GUI Using Python – PyGTK and Glade

A. Jai Sathish Kumar                                     [email protected]      [email protected] 

  

Page 2: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 3: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

PyFLTK            Pygame Pyglet   

PythonCard       PyGTK PySide

PyQt       TkInter    wxPython  

Page 4: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

No Standard

GUI Tool available

Page 5: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

There are

some factors

that decides

the GUI tool

Page 6: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Money

Page 7: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

OR

Linux User Windows User

Page 8: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   Linux and Windows User

Page 9: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

A GNOME User

Page 10: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

A KDE User

Page 11: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

What is

PyGTK ?

Page 12: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

        

+

Page 13: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

  Y

PyGTK 

Page 14: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Easy to create your own GUI

Page 15: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   PyGTK is Free Open Source Software

Page 16: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

PyGTK supports Multiplatform Applications

Page 17: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

What is

GTK ?

Page 18: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

GTK (GIMP ToolKit)

Page 19: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Library for creating 

Graphical User Interfaces

Page 20: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

PyGTKProgramming

Basics

Page 21: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Import  required  Libraries

Page 22: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Create a Window

Page 23: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Pack Widgets into it

Page 24: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Set Appropriate Signals

 to Widgets

Page 25: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Connect Signals to 

Callback Functions

Page 26: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Uses main loopto start  

GTK+ event processing loop

Page 27: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

              Putting it all togetherimport pygtkpygtk.require('2.0')import gtk #import libraries

class WelcomeMsg:def __init__(self):

window = gtk.Window() #create a windowwindow.set_title("Welcome")window.set_border_width(10)window.set_size_request(200,100)window.connect("destroy", self.quit)

vbox = gtk.VBox()window.add(vbox)

button = gtk.Button("Press Me !")button.connect("clicked",self.printMessage,"Welcome To Pycon India 

2009,IISc")vbox.pack_start(button,True,True,0) #pack widgets

Page 28: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

button = gtk.Button("Close")button.connect("clicked",self.quit) #connect signals to callbackvbox.pack_start(button,True,True,5)

window.show_all()

def printMessage(self,widget,data): #callback functionprint data

def quit(self,widget): #callback functiongtk.main_quit()

def main(self):gtk.main() #main loop

if __name__ == "__main__":p = WelcomeMsg()p.main()

Page 29: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Run in the terminal

                                python filename.py

Page 30: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

END of PyGTK

Page 31: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

WELCOMETo

GLADE

Page 32: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

GLADE

Page 33: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

What is 

  Glade ? 

Page 34: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

A

User

Interface 

Designer

Page 35: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

GLADE

Page 36: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

RapidApplication

DevelopmentTool

Page 37: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Used in Many Programming Languages

Page 38: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 39: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

User Interfaces are stored 

inXML format

Page 40: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

GLADEGUI

Designing

Page 41: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

A Drag &

DropInterface

Page 42: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Design starts by adding 

i. Top Levelsii. Containersiii. Controls and Displays 

Page 43: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Top Levels

Page 44: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 45: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Containers

Page 46: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 47: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Controls and

Displays

Page 48: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 49: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 50: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Set the glade file

def __init__(self):self.gladefile = "glade file name"self.wTree = gtk.glade.XML(self.gladefile)

Page 51: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Create a dictionary and Connect it

dic = {"on_mainWindow_destroy" : gtk.main_quit,

}

self.wTree.signal_autoconnect(dic)

Page 52: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Resources

Page 53: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   http://wiki.python.org/moin/GuiProgramming

Page 54: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   http://www.pygtk.org/

Page 55: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   http://glade.gnome.org/

Page 56: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

● Mailing list● IRC● Forums

Page 57: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 58: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 59: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

Page 60: GUI Using Python – PyGTK and Glade - PyCon India · GUI Using Python – PyGTK and Glade ... (GIMP ToolKit) ... python filename.py END of PyGTK WELCOME To GLADE GLADE What is

   

We  thank and  for pictures