[pygtk] Fwd: image problem

A.T.Hofkamp a.t.hofkamp at tue.nl
Mon Jan 12 17:44:38 WST 2009


Hello,

I cannot make heads or tails from your post, it seems like you are asking 
several things at the same time.

i i wrote:
> ---------- Forwarded message ----------
> From: i i <iaidas4 at gmail.com>
>      i am making an application.Its basically a learning game ,I want to set
> the label to a string of random intigers,i also want to show equivalent
> number of images in the box.

I don't see any label code in your source.

Is a label with a "string of random integers" something like "1 2 234 2345 5"?

What would the display look like here?


> say i have a number that takes random.randint(0, 10).
> i want to show images equivalent to the number that is shown in tab.here is
> the code

So with 2, you would show two images.

> self.fixed=self.wTree.get_widget("fixed1")

What is 'self.wTree' here?

>         self.numOne = random.randint(1,10)
>     for i in range(self.numOne):
>         self.image = gtk.Image()

In general, it is easier to seperate structural setup of your widgets from 
filling them.

In your case, that would mean to make 10 image widgets in your __init__() 
(since that is what you need at most).

In a seperate function, you'd draw a random number, and copy the right images 
to the right widgets.

In this way, the number of widgets stays fixed. It may be less pretty but it 
makes the application a lot simpler, which may be good for a first implementation.

(Maybe what you are doing is possible, it kind of depends on what self.wTree 
is. I have never tried having a changing number of widgets in the application.).

 >         self.image.set_from_file("./Pink-Flower-32x32.png")

Here you load the same file over and over again. It is more efficient to load 
it once and make in-memory copies from the loaded image.

> self.image.clear() function clears the image and again reset the previous
> and the new ones .I want to clear the previus images and again set the
> number to the specified number in numOne .how can i do this.

There is no clear() function in your code, so I am kind of lost what you are 
asking here.

If you mean you want to draw another number and display another sequence of 
pictures, then you have to split initial creation of the widgets (which you 
normally do in __init__()) from setting values into the widgets (what I call 
'a seperate function').


Hopefully this answer gives you some clues, or at least some points to discuss 
further,

Sincerely
Albert



More information about the pygtk mailing list