[Tutor] Traffic Light

Alan Gauld alan.gauld at btinternet.com
Sun Jan 20 02:02:59 CET 2013


On 19/01/13 23:29, anthonym wrote:
> Sure thing.  Here is the code.  And after that is the box I get with the
> radio buttons but no shapes.

It all runs fine for me. I'm not sure what you are expecting but it does 
exactly what I'd expect...

The shapes aren't there because you don't draw them. you have some 
functions that might draw shapes but you never call them. And the 
drawOval function gets overwritten twice, so only the last version 
actually exists. You need to call that function with the params or 
rename it something like drawTopLeftOval(). But frankly the generic 
version is better, just keep it to one and pass the values in.

>      # Display a rectangle
>      def displayRect(self):
>          self.canvas.create_rectangle(10, 10, 100, 100, tages = "rect")
>
>      # Display a Oval for the top light
>      def displayOval(self):
>          self.canvas.create_oval(10, 10, 10, 10)
>
>      # Display an Oval for the middle light
>      def displayOval(self):
>          self.canvas.create_oval(20, 20, 20, 20)
>
>      # Display an Oval for the bottom light
>      def displayOval(self):
>          self.canvas.create_oval(30, 30, 30, 30)

Only the last version is actually available in your program it 
overwrites the earlier versions.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list