SlideShare a Scribd company logo
1 of 13
Download to read offline
PyGTK
i
AbouttheTutorial
PyGTK is a set of wrappers written in Python and C for GTK + GUI library. It is part of the
GNOME project. It offers comprehensive tools for building desktop applications in Python.
This tutorial discusses the basic functionalities of the different widgets found in the toolkit.
Audience
This tutorial has been prepared for beginners to help them understand the basic concepts
of PyGTK. Advanced programmers can also draw benefits from this tutorial.
Prerequisites
Before proceeding further with this tutorial, it is recommended that you have a reasonable
knowledge of Python programming language.
Copyright&Disclaimer
© Copyright 2016 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com.
PyGTK
ii
TableofContents
About the Tutorial ............................................................................................................................................i
Audience...........................................................................................................................................................i
Prerequisites.....................................................................................................................................................i
Copyright & Disclaimer .....................................................................................................................................i
Table of Contents.............................................................................................................................................ii
1. PYGTK – INTRODUCTION ...................................................................................................... 1
2. PYGTK – ENVIRONMENT........................................................................................................ 3
3. PYGTK – HELLO WORLD ........................................................................................................ 4
4. PYGTK – IMPORTANT CLASSES ........................................................................................... 6
5. PYGTK – WINDOW CLASS ...................................................................................................... 8
6. PYGTK – BUTTON CLASS......................................................................................................10
7. PYGTK – LABEL CLASS ..........................................................................................................12
8. PYGTK – ENTRY CLASS .........................................................................................................13
9. PYGTK – SIGNAL HANDLING...............................................................................................15
10. PYGTK – EVENT HANDLING ............................................................................................18
11. PYGTK – CONTAINERS ......................................................................................................20
12. PYGTK – BOX CLASS...........................................................................................................23
13. PYGTK – BUTTONBOX CLASS..........................................................................................26
14. PYGTK – ALIGNMENT CLASS...........................................................................................28
15. PYGTK – EVENTBOX CLASS .............................................................................................30
PyGTK
iii
16. PYGTK – LAYOUT CLASS...................................................................................................32
17. PYGTK – COMBOBOX CLASS............................................................................................34
18. PYGTK – TOGGLEBUTTON CLASS..................................................................................39
19. PYGTK – CHECKBUTTON CLASS.....................................................................................42
20. PYGTK – RADIOBUTTON CLASS.....................................................................................44
21. PYGTK – MENUBAR, MENU & MENUITEM ..................................................................46
22. PYGTK – TOOLBAR CLASS................................................................................................51
23. PYGTK – ADJUSTMENT CLASS ........................................................................................55
24. PYGTK – RANGE CLASS......................................................................................................56
25. PYGTK – SCALE CLASS.......................................................................................................57
26. PYGTK — SCROLLBAR CLASS .........................................................................................58
27. PYGTK – DIALOG CLASS....................................................................................................61
28. PYGTK — MESSAGEDIALOG CLASS...............................................................................67
29. PYGTK – ABOUTDIALOG CLASS .....................................................................................69
30. PYGTK – FONT SELECTION DIALOG..............................................................................71
31. PYGTK – COLOR SELCTION DIALOG .............................................................................73
32. PYGTK – FILE CHOOSER DIALOG...................................................................................75
33. PYGTK – NOTEBOOK CLASS ............................................................................................77
34. PYGTK – FRAME CLASS .....................................................................................................81
35. PYGTK – ASPECTFRAME CLASS......................................................................................84
PyGTK
iv
36. PYGTK – TREEVIEW CLASS..............................................................................................87
37. PYGTK – PANED CLASS .....................................................................................................95
38. PYGTK – STATUSBAR CLASS ...........................................................................................98
39. PYGTK – PROGRESSBAR CLASS................................................................................... 101
40. PYGTK – VIEWPORT CLASS .......................................................................................... 104
41. PYGTK – SCROLLEDWINDOW CLASS......................................................................... 105
42. PYGTK – ARROW CLASS................................................................................................. 108
43. PYGTK – IMAGE CLASS ................................................................................................... 111
44. PYGTK – DRAWINGAREA CLASS ................................................................................. 113
45. PYGTK – SPINBUTTON CLASS...................................................................................... 116
46. PYGTK – CALENDAR CLASS........................................................................................... 120
47. PYGTK – CLIPBOARD CLASS......................................................................................... 125
48. PYGTK – RULER CLASS................................................................................................... 128
49. PYGTK – TIMEOUT .......................................................................................................... 131
50. PYGTK — DRAG AND DROP ......................................................................................... 134
PyGTK
1
PyGTK is a set of wrappers written in Python and C for GTK + GUI library. It is part of the
GNOME project. It offers comprehensive tools for building desktop applications in Python.
Python bindings for other popular GUI libraries are also available.
PyQt is a Python port of QT library. Our PyQt tutorial can be found here. Similarly,
wxPython toolkit is Python binding for wxWidgets, another popular cross-platform GUI
library. Our wxPython tutorial is available here.
GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user
interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from
small one-off tools to complete application suites.
GTK+ has been designed from the ground up to support a wide range of languages. PyGTK
is a Python wrapper for GTK+.
GTK+ is built around the following four libraries:
 Glib — A low-level core library that forms the basis of GTK+. It provides data
structure handling for C.
 Pango — A library for layout and rendering of text with an emphasis on
internationalization.
 Cairo — A library for 2D graphics with support for multiple output devices
(including the X Window System, Win32)
 ATK — A library for a set of interfaces providing accessibility tools such as screen
readers, magnifiers, and alternative input devices.
1. PyGTK – Introduction
PyGTK
2
PyGTK eases the process and helps you create programs with a graphical user
interface using the Python programming language. The underlying GTK+ library provides
all kinds of visual elements and utilities for it to develop full-featured applications for the
GNOME Desktop. PyGTK is a cross-platform library. It is a free software distributed under
the LGPL license.
PyGTK is built around GTK + 2.x. In order to build applications for GTK +3, PyGObject
bindings are also available.
PyGTK
3
PyGTK for Microsoft Windows
The installation of PyGTK for Microsoft Windows involves the following steps:
 Step 1: Install a 32-bit Python interpreter (latest Python 2.7 distribution)
 Step 2: Download and install GTK+ runtime.
 Step 3: Download and install PyGTK from the following URL:
(http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/)
 Step 4: It is also recommended that you download PyCairo and PyGobject modules
from the following URLs:
(http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/)
(http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/)
 Step 5: For convenience, all-in-one installer which handles all of the PyGTK
dependencies is also available. Download and install the latest all-in-one installer
for Windows from the following URL:
(http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-
2.24.0.win32-py2.7.msi)
PyGTK for Linux
PyGTK is included in most Linux distributions (including Debian, Fedora, Ubuntu,RedHat
etc); the source code can also be downloaded and compiled from the following URL
http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.24/
2. PyGTK – Environment
PyGTK
4
Creating a window using PyGTK is very simple. To proceed, we first need to import the gtk
module in our code.
import gtk
The gtk module contains the gtk.Window class. Its object constructs a toplevel window.
We derive a class from gtk.Window.
class PyApp(gtk.Window):
Define the constructor and call the show_all() method of the gtk.window class.
def __init__(self):
super(PyApp, self).__init__()
self.show_all()
We now have to declare the object of this class and start an event loop by calling its main()
method.
PyApp()
gtk.main()
It is recommended we add a label “Hello World” in the parent window.
label = gtk.Label("Hello World")
self.add(label)
The following is a complete code to display “Hello World”:
import gtk
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_default_size(300,200)
self.set_title("Hello World in PyGTK")
3. PyGTK – Hello World
PyGTK
5
label = gtk.Label("Hello World")
self.add(label)
self.show_all()
PyApp()
gtk.main()
The implementation of the above code will yield the following output:
PyGTK
6
The PyGTK module contains various widgets. gtk.Object class acts as the base class for
most of the widgets as well as for some non-widget classes. The toplevel window for
desktop applications using PyGTK is provided by gtk.Window class. The following table lists
the important widgets and their functions:
gtk.Widget
This is a gtk.base class for all PyGTK widgets. gtk.Widget provides
a common set of methods and signals for the widgets.
gtk.Window
This is a toplevel window that holds one child widget. gtk.Window
is a display area decorated with a title bar, and items to allow the
user to close, resize and move the window.
gtk.Button
This is a pushbutton widget that issues a signal when clicked.
gtk.Button is usually displayed as a pushbutton with a text label
and is generally used to attach a callback function.
gtk.Entry This is a single line text entry widget.
gtk.Label This widget displays a limited amount of read-only text.
gtk.ButtonBox This is a base class for widgets that contains multiple buttons.
gtk.HBox
This is a container that organizes its child widgets into a single
horizontal row.
gtk.VBox
This is a container that organizes its child widgets into a single
column.
gtk.Fixed
This is a container that can place child widgets at fixed positions
and with fixed sizes, given in pixels.
gtk.Layout
This provides infinite scrollable area containing child widgets and
custom drawing.
gtk.MenuItem
This widget implements the appearance and behavior of menu
items. The derived widget subclasses of the gtk.MenuItem are the
only valid children of menus. When selected by a user, they can
display a popup menu or invoke an associated function or method
gtk.Menu
This is a dropdown menu consisting of a list of MenuItem objects
which can be navigated and activated by the user to perform
application functions.
gtk.MenuBar
This displays the menu items horizontally in an application window
or dialog.
gtk.ComboBox This widget is used to choose from a list of items.
gtk.Scale
This is a horizontal or vertical slider control to select a numeric
value.
4. PyGTK – Important Classes
PyGTK
7
gtk.Scrollbar This displays a horizontal or vertical scrollbar.
gtk.ProgressBar This is used to display the progress of a long running operation.
gtk.Dialog This displays a popup window for user information and action.
gtk.Notebook
This widget is a container whose children are overlapping pages
that can be switched between using tab labels.
gtk.Paned
This is a base class for widgets with two panes, arranged either
horizontally or vertically. Child widgets are added to the panes of
the widget. The division between the two children can be adjusted
by the user.
gtk.TextView This widget displays the contents of a TextBuffer object.
gtk.Toolbar
This container holds and manages a set of buttons and widgets in
a horizontal or vertical bar.
gtk.TreeView
This widget displays the contents of standard TreeModel (ListStore,
TreeStore, TreeModelSort)
gtk.DrawingArea
This widget helps in creating custom user interface elements.
gtk.DrawingArea is essentially a blank widget containing a
window that you can draw on.
gtk.Calendar This widget displays a calendar and allows the user to select a date.
gtk.Viewport This widget displays a portion of a larger widget.
PyGTK
8
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://store.tutorialspoint.com

More Related Content

Similar to Pygtk tutorial

A Whirlwind Tour Of Python
A Whirlwind Tour Of PythonA Whirlwind Tour Of Python
A Whirlwind Tour Of PythonAsia Smith
 
Gtk development-using-glade-3
Gtk development-using-glade-3Gtk development-using-glade-3
Gtk development-using-glade-3caezsar
 
The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196Mahmoud Samir Fayed
 
Leveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS ApproachLeveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS ApproachGerry James
 
Rejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform GainRejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform GainŁukasz Piątkowski
 
wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for PythonwxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for PythonUmar Yusuf
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfVisionAcademyProfSac
 
Introduction to Git for Network Engineers (Lab Guide)
Introduction to Git for Network Engineers (Lab Guide)Introduction to Git for Network Engineers (Lab Guide)
Introduction to Git for Network Engineers (Lab Guide)Joel W. King
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?Janel Heilbrunn
 
So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?ICS
 
Why should I learn python
Why should I learn pythonWhy should I learn python
Why should I learn pythongrinu
 

Similar to Pygtk tutorial (20)

InfoPay v5 Developers Manual
InfoPay v5 Developers ManualInfoPay v5 Developers Manual
InfoPay v5 Developers Manual
 
A Whirlwind Tour Of Python
A Whirlwind Tour Of PythonA Whirlwind Tour Of Python
A Whirlwind Tour Of Python
 
Gtk development-using-glade-3
Gtk development-using-glade-3Gtk development-using-glade-3
Gtk development-using-glade-3
 
Mpi4py
Mpi4pyMpi4py
Mpi4py
 
The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196The Ring programming language version 1.7 book - Part 89 of 196
The Ring programming language version 1.7 book - Part 89 of 196
 
Leveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS ApproachLeveraging Open Source GIS with Python: A QGIS Approach
Leveraging Open Source GIS with Python: A QGIS Approach
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Rejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform GainRejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform Gain
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for PythonwxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdf
 
Introduction to Git for Network Engineers (Lab Guide)
Introduction to Git for Network Engineers (Lab Guide)Introduction to Git for Network Engineers (Lab Guide)
Introduction to Git for Network Engineers (Lab Guide)
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?
 
So I downloaded Qt, Now What?
So I downloaded Qt, Now What?So I downloaded Qt, Now What?
So I downloaded Qt, Now What?
 
Why should I learn python
Why should I learn pythonWhy should I learn python
Why should I learn python
 
Python
Python Python
Python
 

More from HarikaReddy115

Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorialHarikaReddy115
 
Wireless communication tutorial
Wireless communication tutorialWireless communication tutorial
Wireless communication tutorialHarikaReddy115
 
Control systems tutorial
Control systems tutorialControl systems tutorial
Control systems tutorialHarikaReddy115
 
Computer logical organization_tutorial
Computer logical organization_tutorialComputer logical organization_tutorial
Computer logical organization_tutorialHarikaReddy115
 
Computer fundamentals tutorial
Computer fundamentals tutorialComputer fundamentals tutorial
Computer fundamentals tutorialHarikaReddy115
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorialHarikaReddy115
 
Communication technologies tutorial
Communication technologies tutorialCommunication technologies tutorial
Communication technologies tutorialHarikaReddy115
 
Behavior driven development_tutorial
Behavior driven development_tutorialBehavior driven development_tutorial
Behavior driven development_tutorialHarikaReddy115
 
Basics of computers_tutorial
Basics of computers_tutorialBasics of computers_tutorial
Basics of computers_tutorialHarikaReddy115
 
Basics of computer_science_tutorial
Basics of computer_science_tutorialBasics of computer_science_tutorial
Basics of computer_science_tutorialHarikaReddy115
 
Basic electronics tutorial
Basic electronics tutorialBasic electronics tutorial
Basic electronics tutorialHarikaReddy115
 
Artificial neural network_tutorial
Artificial neural network_tutorialArtificial neural network_tutorial
Artificial neural network_tutorialHarikaReddy115
 
Artificial intelligence tutorial
Artificial intelligence tutorialArtificial intelligence tutorial
Artificial intelligence tutorialHarikaReddy115
 
Antenna theory tutorial
Antenna theory tutorialAntenna theory tutorial
Antenna theory tutorialHarikaReddy115
 
Analog communication tutorial
Analog communication tutorialAnalog communication tutorial
Analog communication tutorialHarikaReddy115
 

More from HarikaReddy115 (20)

Dbms tutorial
Dbms tutorialDbms tutorial
Dbms tutorial
 
Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorial
 
Wireless communication tutorial
Wireless communication tutorialWireless communication tutorial
Wireless communication tutorial
 
Cryptography tutorial
Cryptography tutorialCryptography tutorial
Cryptography tutorial
 
Cosmology tutorial
Cosmology tutorialCosmology tutorial
Cosmology tutorial
 
Control systems tutorial
Control systems tutorialControl systems tutorial
Control systems tutorial
 
Computer logical organization_tutorial
Computer logical organization_tutorialComputer logical organization_tutorial
Computer logical organization_tutorial
 
Computer fundamentals tutorial
Computer fundamentals tutorialComputer fundamentals tutorial
Computer fundamentals tutorial
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorial
 
Communication technologies tutorial
Communication technologies tutorialCommunication technologies tutorial
Communication technologies tutorial
 
Biometrics tutorial
Biometrics tutorialBiometrics tutorial
Biometrics tutorial
 
Behavior driven development_tutorial
Behavior driven development_tutorialBehavior driven development_tutorial
Behavior driven development_tutorial
 
Basics of computers_tutorial
Basics of computers_tutorialBasics of computers_tutorial
Basics of computers_tutorial
 
Basics of computer_science_tutorial
Basics of computer_science_tutorialBasics of computer_science_tutorial
Basics of computer_science_tutorial
 
Basic electronics tutorial
Basic electronics tutorialBasic electronics tutorial
Basic electronics tutorial
 
Auditing tutorial
Auditing tutorialAuditing tutorial
Auditing tutorial
 
Artificial neural network_tutorial
Artificial neural network_tutorialArtificial neural network_tutorial
Artificial neural network_tutorial
 
Artificial intelligence tutorial
Artificial intelligence tutorialArtificial intelligence tutorial
Artificial intelligence tutorial
 
Antenna theory tutorial
Antenna theory tutorialAntenna theory tutorial
Antenna theory tutorial
 
Analog communication tutorial
Analog communication tutorialAnalog communication tutorial
Analog communication tutorial
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Pygtk tutorial

  • 1.
  • 2. PyGTK i AbouttheTutorial PyGTK is a set of wrappers written in Python and C for GTK + GUI library. It is part of the GNOME project. It offers comprehensive tools for building desktop applications in Python. This tutorial discusses the basic functionalities of the different widgets found in the toolkit. Audience This tutorial has been prepared for beginners to help them understand the basic concepts of PyGTK. Advanced programmers can also draw benefits from this tutorial. Prerequisites Before proceeding further with this tutorial, it is recommended that you have a reasonable knowledge of Python programming language. Copyright&Disclaimer © Copyright 2016 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com.
  • 3. PyGTK ii TableofContents About the Tutorial ............................................................................................................................................i Audience...........................................................................................................................................................i Prerequisites.....................................................................................................................................................i Copyright & Disclaimer .....................................................................................................................................i Table of Contents.............................................................................................................................................ii 1. PYGTK – INTRODUCTION ...................................................................................................... 1 2. PYGTK – ENVIRONMENT........................................................................................................ 3 3. PYGTK – HELLO WORLD ........................................................................................................ 4 4. PYGTK – IMPORTANT CLASSES ........................................................................................... 6 5. PYGTK – WINDOW CLASS ...................................................................................................... 8 6. PYGTK – BUTTON CLASS......................................................................................................10 7. PYGTK – LABEL CLASS ..........................................................................................................12 8. PYGTK – ENTRY CLASS .........................................................................................................13 9. PYGTK – SIGNAL HANDLING...............................................................................................15 10. PYGTK – EVENT HANDLING ............................................................................................18 11. PYGTK – CONTAINERS ......................................................................................................20 12. PYGTK – BOX CLASS...........................................................................................................23 13. PYGTK – BUTTONBOX CLASS..........................................................................................26 14. PYGTK – ALIGNMENT CLASS...........................................................................................28 15. PYGTK – EVENTBOX CLASS .............................................................................................30
  • 4. PyGTK iii 16. PYGTK – LAYOUT CLASS...................................................................................................32 17. PYGTK – COMBOBOX CLASS............................................................................................34 18. PYGTK – TOGGLEBUTTON CLASS..................................................................................39 19. PYGTK – CHECKBUTTON CLASS.....................................................................................42 20. PYGTK – RADIOBUTTON CLASS.....................................................................................44 21. PYGTK – MENUBAR, MENU & MENUITEM ..................................................................46 22. PYGTK – TOOLBAR CLASS................................................................................................51 23. PYGTK – ADJUSTMENT CLASS ........................................................................................55 24. PYGTK – RANGE CLASS......................................................................................................56 25. PYGTK – SCALE CLASS.......................................................................................................57 26. PYGTK — SCROLLBAR CLASS .........................................................................................58 27. PYGTK – DIALOG CLASS....................................................................................................61 28. PYGTK — MESSAGEDIALOG CLASS...............................................................................67 29. PYGTK – ABOUTDIALOG CLASS .....................................................................................69 30. PYGTK – FONT SELECTION DIALOG..............................................................................71 31. PYGTK – COLOR SELCTION DIALOG .............................................................................73 32. PYGTK – FILE CHOOSER DIALOG...................................................................................75 33. PYGTK – NOTEBOOK CLASS ............................................................................................77 34. PYGTK – FRAME CLASS .....................................................................................................81 35. PYGTK – ASPECTFRAME CLASS......................................................................................84
  • 5. PyGTK iv 36. PYGTK – TREEVIEW CLASS..............................................................................................87 37. PYGTK – PANED CLASS .....................................................................................................95 38. PYGTK – STATUSBAR CLASS ...........................................................................................98 39. PYGTK – PROGRESSBAR CLASS................................................................................... 101 40. PYGTK – VIEWPORT CLASS .......................................................................................... 104 41. PYGTK – SCROLLEDWINDOW CLASS......................................................................... 105 42. PYGTK – ARROW CLASS................................................................................................. 108 43. PYGTK – IMAGE CLASS ................................................................................................... 111 44. PYGTK – DRAWINGAREA CLASS ................................................................................. 113 45. PYGTK – SPINBUTTON CLASS...................................................................................... 116 46. PYGTK – CALENDAR CLASS........................................................................................... 120 47. PYGTK – CLIPBOARD CLASS......................................................................................... 125 48. PYGTK – RULER CLASS................................................................................................... 128 49. PYGTK – TIMEOUT .......................................................................................................... 131 50. PYGTK — DRAG AND DROP ......................................................................................... 134
  • 6. PyGTK 1 PyGTK is a set of wrappers written in Python and C for GTK + GUI library. It is part of the GNOME project. It offers comprehensive tools for building desktop applications in Python. Python bindings for other popular GUI libraries are also available. PyQt is a Python port of QT library. Our PyQt tutorial can be found here. Similarly, wxPython toolkit is Python binding for wxWidgets, another popular cross-platform GUI library. Our wxPython tutorial is available here. GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off tools to complete application suites. GTK+ has been designed from the ground up to support a wide range of languages. PyGTK is a Python wrapper for GTK+. GTK+ is built around the following four libraries:  Glib — A low-level core library that forms the basis of GTK+. It provides data structure handling for C.  Pango — A library for layout and rendering of text with an emphasis on internationalization.  Cairo — A library for 2D graphics with support for multiple output devices (including the X Window System, Win32)  ATK — A library for a set of interfaces providing accessibility tools such as screen readers, magnifiers, and alternative input devices. 1. PyGTK – Introduction
  • 7. PyGTK 2 PyGTK eases the process and helps you create programs with a graphical user interface using the Python programming language. The underlying GTK+ library provides all kinds of visual elements and utilities for it to develop full-featured applications for the GNOME Desktop. PyGTK is a cross-platform library. It is a free software distributed under the LGPL license. PyGTK is built around GTK + 2.x. In order to build applications for GTK +3, PyGObject bindings are also available.
  • 8. PyGTK 3 PyGTK for Microsoft Windows The installation of PyGTK for Microsoft Windows involves the following steps:  Step 1: Install a 32-bit Python interpreter (latest Python 2.7 distribution)  Step 2: Download and install GTK+ runtime.  Step 3: Download and install PyGTK from the following URL: (http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/)  Step 4: It is also recommended that you download PyCairo and PyGobject modules from the following URLs: (http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/) (http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/)  Step 5: For convenience, all-in-one installer which handles all of the PyGTK dependencies is also available. Download and install the latest all-in-one installer for Windows from the following URL: (http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk- 2.24.0.win32-py2.7.msi) PyGTK for Linux PyGTK is included in most Linux distributions (including Debian, Fedora, Ubuntu,RedHat etc); the source code can also be downloaded and compiled from the following URL http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.24/ 2. PyGTK – Environment
  • 9. PyGTK 4 Creating a window using PyGTK is very simple. To proceed, we first need to import the gtk module in our code. import gtk The gtk module contains the gtk.Window class. Its object constructs a toplevel window. We derive a class from gtk.Window. class PyApp(gtk.Window): Define the constructor and call the show_all() method of the gtk.window class. def __init__(self): super(PyApp, self).__init__() self.show_all() We now have to declare the object of this class and start an event loop by calling its main() method. PyApp() gtk.main() It is recommended we add a label “Hello World” in the parent window. label = gtk.Label("Hello World") self.add(label) The following is a complete code to display “Hello World”: import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_default_size(300,200) self.set_title("Hello World in PyGTK") 3. PyGTK – Hello World
  • 10. PyGTK 5 label = gtk.Label("Hello World") self.add(label) self.show_all() PyApp() gtk.main() The implementation of the above code will yield the following output:
  • 11. PyGTK 6 The PyGTK module contains various widgets. gtk.Object class acts as the base class for most of the widgets as well as for some non-widget classes. The toplevel window for desktop applications using PyGTK is provided by gtk.Window class. The following table lists the important widgets and their functions: gtk.Widget This is a gtk.base class for all PyGTK widgets. gtk.Widget provides a common set of methods and signals for the widgets. gtk.Window This is a toplevel window that holds one child widget. gtk.Window is a display area decorated with a title bar, and items to allow the user to close, resize and move the window. gtk.Button This is a pushbutton widget that issues a signal when clicked. gtk.Button is usually displayed as a pushbutton with a text label and is generally used to attach a callback function. gtk.Entry This is a single line text entry widget. gtk.Label This widget displays a limited amount of read-only text. gtk.ButtonBox This is a base class for widgets that contains multiple buttons. gtk.HBox This is a container that organizes its child widgets into a single horizontal row. gtk.VBox This is a container that organizes its child widgets into a single column. gtk.Fixed This is a container that can place child widgets at fixed positions and with fixed sizes, given in pixels. gtk.Layout This provides infinite scrollable area containing child widgets and custom drawing. gtk.MenuItem This widget implements the appearance and behavior of menu items. The derived widget subclasses of the gtk.MenuItem are the only valid children of menus. When selected by a user, they can display a popup menu or invoke an associated function or method gtk.Menu This is a dropdown menu consisting of a list of MenuItem objects which can be navigated and activated by the user to perform application functions. gtk.MenuBar This displays the menu items horizontally in an application window or dialog. gtk.ComboBox This widget is used to choose from a list of items. gtk.Scale This is a horizontal or vertical slider control to select a numeric value. 4. PyGTK – Important Classes
  • 12. PyGTK 7 gtk.Scrollbar This displays a horizontal or vertical scrollbar. gtk.ProgressBar This is used to display the progress of a long running operation. gtk.Dialog This displays a popup window for user information and action. gtk.Notebook This widget is a container whose children are overlapping pages that can be switched between using tab labels. gtk.Paned This is a base class for widgets with two panes, arranged either horizontally or vertically. Child widgets are added to the panes of the widget. The division between the two children can be adjusted by the user. gtk.TextView This widget displays the contents of a TextBuffer object. gtk.Toolbar This container holds and manages a set of buttons and widgets in a horizontal or vertical bar. gtk.TreeView This widget displays the contents of standard TreeModel (ListStore, TreeStore, TreeModelSort) gtk.DrawingArea This widget helps in creating custom user interface elements. gtk.DrawingArea is essentially a blank widget containing a window that you can draw on. gtk.Calendar This widget displays a calendar and allows the user to select a date. gtk.Viewport This widget displays a portion of a larger widget.
  • 13. PyGTK 8 End of ebook preview If you liked what you saw… Buy it from our store @ https://store.tutorialspoint.com