Here is the simple example.
For more gc manupulations, see description.py in pygtk distribution.
from gtk import *
import whrandom
win = GtkWindow()
win.connect('destroy', mainquit)
da = GtkDrawingArea()
win.add(da)
da.size(300, 400)
da.show()
# wait util DrawingArea Window be realized
win.show_now()
gc = da.get_window().new_gc()
gc.line_width = 2
cmap = da.get_colormap()
colorname = ["black", "white", "red", "blue", "green", "yellow", "cyan"]
colortable = map(lambda name,cmap=cmap: cmap.alloc(name), colorname)
def random_draw(da=da):
x, y, width, height = da.get_allocation()
x = whrandom.randint(x,x+width-3)
y = whrandom.randint(y,y+height-3)
color = colortable[whrandom.randint(0, len(colortable)-1)]
gc.foreground = color
da.draw_line(gc, x, y, x+2,y+2)
# repeat me.
return 1
timeout_add(20, random_draw)
mainloop()
On Wed, 28 Apr 1999, Tim Voght wrote:
> Hi,
>
> I've just joined this list, and I'd like to start by saying I really
> like pygtk. It's very nicely done.
> I love programming in Python, and it's great to have a nice toolkit like
> gtk available.
>
> My first pygtk project involves using a DrawingArea for 2d data
> plotting. I started by grabbing the scribble example included in the
> documentation. The plots are drawn as a series of lines segments between
> points using draw_line().
>
> It works great for drawing black plots on white. For example, I'm using
> calls like:
>
> draw_line(pixmap, drawing_area.get_style().black_gc,
> lastX, lastY, thisX, thisY)
>
> Now how do I draw lines of different colors? I'd like to draw a few
> plots on the drawing area; each of a different color. I'm not a Gtk or X
> programming expert. The Gtk example I have found makes sense, but
> doesn't seem to apply to PyGtk (i.e. it uses a set_foreground() call
> that is apparently not available to DrawingArea).
> I suspect the solution involves using new_gc() in some way, but I'm
> pretty lost. Can anybody help?
>
> Tim Voght
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
>
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]