PyGTK Tutorial
PyGTK Useful Resources
Selected Reading
- PyGTK - Drag and Drop
- PyGTK - Timeout
- PyGTK - Ruler Class
- PyGTK - Clipboard Class
- PyGTK - Calendar Class
- PyGTK - SpinButton Class
- PyGTK - DrawingArea Class
- PyGTK - Image Class
- PyGTK - Arrow Class
- PyGTK - Scrolledwindow Class
- PyGTK - Viewport Class
- PyGTK - ProgressBar Class
- PyGTK - Statusbar Class
- PyGTK - Paned Class
- PyGTK - TreeView Class
- PyGTK - AspectFrame Class
- PyGTK - Frame Class
- PyGTK - Notebook Class
- PyGTK - File Chooser Dialog
- PyGTK - Color Selection Dialog
- PyGTK - Font Selection Dialog
- PyGTK - AboutDialog Class
- PyGTK - MessageDialog Class
- PyGTK - Dialog Class
- PyGTK - Scrollbar Class
- PyGTK - Scale Class
- PyGTK - Range Class
- PyGTK - Adjustment Class
- PyGTK - Toolbar Class
- PyGTK - MenuBar, Menu & MenuItem
- PyGTK - RadioButton Class
- PyGTK - CheckButton Class
- PyGTK - ToggleButton Class
- PyGTK - ComboBox Class
- PyGTK - Layout Class
- PyGTK - EventBox Class
- PyGTK - Alignment Class
- PyGTK - ButtonBox Class
- PyGTK - Box Class
- PyGTK - Containers
- PyGTK - Event Handling
- PyGTK - Signal Handling
- PyGTK - Entry Class
- PyGTK - Label CLass
- PyGTK - Button Class
- PyGTK - Window Class
- PyGTK - Important Classes
- PyGTK - Hello World
- PyGTK - Environment
- PyGTK - Introduction
- PyGTK - Home
PyGTK Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyGTK - Hello World
PyGTK - Hello World
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 calpng 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") 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 −
Advertisements