pyGTK identify a button
Cousin Stanley
cousinstanley at gmail.com
Wed May 25 12:22:36 EDT 2011
Tracubik wrote:
> Hi all,
> i'm trying to write a simple windows with two button in GTK,
> i need a way to identify wich button is pressed.
> ....
#!/usr/bin/env python
import gtk
def console_display( button , args ) :
a0 , a1 , a2 = args
print ' %s .... %s %s ' % ( a0 , a1 , a2 )
window = gtk.Window()
window.set_title( "gtk.buttons.01" )
window.set_size_request( 300 , -1 )
window.set_position( gtk.WIN_POS_CENTER )
window.connect( "destroy" , gtk.main_quit )
# Create VBox and add in Window
vbox = gtk.VBox()
window.add( vbox )
# Create buttons
dict_buttons = {
12 : [ 'OneTwo' , 'Buckle ' , 'My Shoe' ] ,
34 : [ 'TreFor' , 'Shut ' , 'The Door' ] ,
56 : [ 'FivSix' , 'Pick ' , 'Up Sticks' ] ,
78 : [ 'SvnAte' , 'Lay ' , 'Them Straight' ] ,
910 : [ 'NinTen' , 'Big ' , 'Fat Hen' ] }
list_keys = dict_buttons.keys()
list_keys.sort()
for this_button in list_keys :
this_name = dict_buttons[ this_button ][ 0 ]
b = gtk.Button( this_name )
b.set_name( this_name )
b.connect( "clicked" , console_display , dict_buttons[ this_button ] )
vbox.pack_start( b )
window.show_all()
gtk.main()
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list