Pycon India 2009, Iisc: Gui Using Python - Pygtk and Glade
Pycon India 2009, Iisc: Gui Using Python - Pygtk and Glade
GUIUsingPythonPyGTKandGlade
A.JaiSathishKumarS.Rajeswari
[email protected]
[email protected]
PyFLTKPygame
Pyglet
PythonCardPyGTK
PySide
PyQt
TkInter
wxPython
NoStandard
GUIToolavailable
Thereare
somefactors
thatdecides
theGUItool
Money
OR
LinuxUser
WindowsUser
LinuxandWindowsUser
AGNOMEUser
AKDEUser
What
is
PyGTK?
PyGTK
EasytocreateyourownGUI
PyGTKisFreeOpenSourceSoftware
PyGTKsupportsMultiplatformApplications
What
is
GTK?
GTK(GIMPToolKit)
Library
forcreating
GraphicalUserInterfaces
PyGTK
Programming
Basics
Import
required
Libraries
CreateaWindow
Pack
Widgetsintoit
Set
AppropriateSignals
to
Widgets
ConnectSignals
to
CallbackFunctions
Usesmainloop
tostart
GTK+event
processingloop
Puttingitalltogether
importpygtk
pygtk.require('2.0')
importgtk
#importlibraries
classWelcomeMsg:
def__init__(self):
window=gtk.Window()
window.set_title("Welcome")
window.set_border_width(10)
window.set_size_request(200,100)
window.connect("destroy",self.quit)
#createawindow
vbox=gtk.VBox()
window.add(vbox)
button=gtk.Button("PressMe!")
button.connect("clicked",self.printMessage,"WelcomeToPyconIndia
2009,IISc")
vbox.pack_start(button,True,True,0)
#packwidgets
button=gtk.Button("Close")
button.connect("clicked",self.quit)
vbox.pack_start(button,True,True,5)
#connectsignalstocallback
window.show_all()
defprintMessage(self,widget,data):
printdata
#callbackfunction
defquit(self,widget):
gtk.main_quit()
#callbackfunction
defmain(self):
gtk.main()
#mainloop
if__name__=="__main__":
p=WelcomeMsg()
p.main()
Runintheterminal
pythonfilename.py
ENDofPyGTK
WELCOME
To
GLADE
GLADE
What
is
Glade?
A
User
Interface
Designer
G
L
A
D
E
Rapid
Application
Development
Tool
UsedinMany
ProgrammingLanguages
User
Interfaces
arestored
in
XMLformat
GLADE
GUI
Designing
ADrag
&
Drop
Interface
Designstartsbyadding
i.TopLevels
ii.Containers
iii.ControlsandDisplays
TopLevels
Containers
Controls
and
Displays
Setthegladefile
def__init__(self):
self.gladefile="gladefilename"
self.wTree=gtk.glade.XML(self.gladefile)
Createadictionary
andConnectit
dic={
"on_mainWindow_destroy":gtk.main_quit,
}
self.wTree.signal_autoconnect(dic)
Resources
http://wiki.python.org/moin/GuiProgramming
http://www.pygtk.org/
http://glade.gnome.org/
Mailinglist
IRC
Forums
Wethank
forpictures
and