Pyglade, gtk, howto write more efficiently, and waste less code?

Pipiten pipiten at gmail.com
Tue Sep 19 10:23:45 EDT 2006


Hi everybody, i` m new in this group, and python so.., my greetings to
everybody here.
I wrote a little program, in wich i do this:
(I have several "Select File" buttons, one for each file (in this case,
an image) wich has an text_entry, so i can add a comment for each
picture.)

def on_button1_clicked(self,widget):
	   """Button 1 pressed"""
	   image_file1 = FileSelection(self)
	   self.path1.set_text(image_file1)
	   self.image1.set_from_file(image_file1)
	   self.image1.show()

   def on_button2_clicked(self,widget):
	   """Button 2 pressed"""
	   image_file2 = FileSelection(self)
 	   self.path2.set_text(image_file2)
	   self.image2.set_from_file(image_file2)
	   self.image2.show()

   def on_button3_clicked(self,widget):
	   """Button 3 pressed"""
	   image_file3 = FileSelection(self)
 	   self.path3.set_text(image_file3)
	   self.image3.set_from_file(image_file3)
	   self.image3.show()

   def on_button4_clicked(self,widget):
	   """Button 4 pressed"""
	   image_file4 = FileSelection(self)
 	   self.path4.set_text(image_file4)
	   self.image4.set_from_file(image_file4)
	   self.image4.show()

   def on_button5_clicked(self,widget):
	   """Output dir button pressed"""
	   outputpath = FileSelection(self)
 	   self.path5.set_text(outputpath)


Is there any way to do this, with a for bucle, or something like that?.
For example, if i want to to the same, 25 times, not to copy and paste.
Does anyone knows how to do that?, write it one time, and flexible to
use many times.
( I think it should be with the variables sent by parameters, isn´t? )



Thanks a lot, have a nice day!




More information about the Python-list mailing list