PyGTK notebook: get current page

Alexander Kapps alex.kapps at web.de
Sat May 7 18:05:16 EDT 2011


On 07.05.2011 17:04, Tracubik wrote:
> Hi all!
> I've made a simple PyGTK program.
> It's a window with a notebook, the notebook have 2 pages
> When changing page, i'ld like to get the id of current page.
>
> I've coded it, but i can get only the previously open page, not the
> current one. This is not a big deal if i have only 2 pages, but it could
> be with 3 or more pages.
>
> Here's the code:
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> # template di finestra in pyGTK
>
> import pygtk
> pygtk.require('2.0')
> import gtk
>
> class FinestraGTK:
>
>      def pippo(self, widget, event, data=None):
>          print "current page: " + str(self.nb.get_current_page() )

According to PyGTK docs, the event handler for the switch_page 
signal should look like this:

def pippo(self, notebook, page, page_num, user_data=None):
     ...

With this method you get the new page number in page_num (or in your 
original method with the misleadingly named "data" argument)


HTH



More information about the Python-list mailing list