Newbie alert !

Adam DePrince adam at cognitcorp.com
Fri Dec 3 08:52:21 EST 2004


On Fri, 2004-12-03 at 06:38, Jean Montambeault wrote:
> I am not only learning Python but programming itself ; reading your 
> posts makes me believe that nobody is that much of a beginner here. Is 
> there a newgroup or list for my type somewhere I can't find it ?
> 
> To illustrate my case this script :
> 
> <CODE>
> 
> # function to draw rings for an Olympic flag
> def rings(size,offsetX,offsetY,coul):
>      x1,y1,x2,y2 = 170, 103, 170, 103,
>      can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
>                       x2+size-offsetX,y2-size+offsetY,\
>                       width=8, outline=coul)
> 
> # **main****main****main****main****main****main**
> 
> fen1=Tk()
> can1=Canvas(fen1, bg='white', height=206, width=340)
> can1.pack(side=LEFT)
> 
> bou_europe=Button(fen1, text='Europe',\
>                    command=rings(41, 100, -22, 'blue'))
> bou_europe.pack( )
> 
> bou_asia=Button(fen1, text='Asia',\
>                    command=rings(size=41, offsetX=50,offsetY=22, 
> coul='yellow'))
> bou_asia.pack( )
> 
> bou_africa=Button(fen1, text='Africa',\
>                    command=rings(size=41, offsetX=0,offsetY=-22, 
> coul='black'))
> bou_africa.pack( )
> 
> bou_australia=Button(fen1, text='Australia',\
>                    command=rings(size=41, offsetX=-50,offsetY=22, 
> coul='dark green'))
> bou_australia.pack( )
> 
> bou_america=Button(fen1, text='America',\
>                    command=rings(size=41, offsetX=-100,offsetY=-22, 
> coul='Red'))
> bou_america.pack( )
> 
> bou_quit=Button(fen1, text='Quit', command=fen1.quit)
> bou_quit.pack(side=BOTTOM)
> 
> fen1.mainloop()
> fen1.destroy()
> 
> </CODE>
> 
> I just cannot figure out why the rings are draw right from the start and 
>   don't wait for their buttons to be pressed before being drawn :  I've 
> written similar functions before to draw lines, rectangles and whatever 
> else with success.

Because Button creates a button on the screen and moves on.  Would it be
correct to say that you want the program to block on the creation of
each button until it was pressed?

Typically, GUI's rely on the notion of a callback.  You create a widget,
assign some function to be called when something happens and then enter
your "mainloop" where you wait.  If you want your rings to be created
with button presses then you should be creating them in the button
callbacks ... 

- Adam
> 
> Using Python 2.3, IDLE and Win2k.
> 
> Thanks for your time
> 
> Jean Montambeault
Adam DePrince 
973-723-8597 cell voice/tdd
973-983-7576 home voice/tdd




More information about the Python-list mailing list