- 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 - Event Handpng
In addition to the signal mechanism, window system events can also be connected to callback functions. Window resizing, key press, scroll event etc. are some of common window system events. These events are reported to apppcation s main loop. From there, they are passed along via signals to the callback functions.
Some of the system events are psted below −
button_press_event
button_release_event
scroll_event
motion_notify_event
delete_event
destroy_event
expose_event
key_press_event
key_release_event
The connect() method is used to associate the event with callback function following the syntax −
Object.connect(name, function, data)
Here, name stands for the string corresponding to the name of event which is to be captured. And, function is name of the callback function that is to be called when an event occurs. Data is the argument to be passed on to the callback function.
Hence, the following code connects a Button widget and captures the button_press event −
self.btn.connect("button_press_event", self.hello)
The following will be the Prototype of hello() function −
def hello(self,widget,event):
Example
The following is the code for button event handler −
import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("Hello World in PyGTK") self.set_default_size(400,300) self.set_position(gtk.WIN_POS_CENTER) self.label = gtk.Label("Enter name") self.entry = gtk.Entry() self.btn = gtk.Button("Say Hello") self.btn.connect("button_press_event", self.hello) fixed = gtk.Fixed() fixed.put(self.label, 100,100) fixed.put(self.entry, 100,125) fixed.put(self.btn,100,150) self.add(fixed) self.show_all() def hello(self,widget,event): print "hello",self.entry.get_text() PyApp() gtk.main()
When you run the above code, it displays the following output on the console −
Hello TutorialsPointAdvertisements