Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:06:02+00:00 2026-06-15T11:06:02+00:00

I draw an oval into a canvas which works perfect also it show color

  • 0

I draw an oval into a canvas which works perfect also it show color red and the loops runs fine too cause I can see the print. Its supposed to change the color ever 1000ms. But its not changing the color?

def draw_light(self):
        w = tk.Canvas(self.frame_Light)
        w.pack()
        w.create_oval(10, 10, 30, 30, fill="yellow", tags="light")

        if self.light_on:
            w.itemconfig("light", fill="blue")
            self.light_on = False
            print "on"
        else:
            w.itemconfig("light", fill="red")
            self.light_on = True
            print "of"

        self.app.after(1000, self.draw_light)

UPDATE
changed the code to your suggestions still generates only the red canvas thats it

def draw_light(self):
    self.ligth_canvas = tk.Canvas(self.frame_Light)
    self.ligth_canvas.pack()
    self.ligth_canvas.create_oval(10, 10, 30, 30, fill="yellow", tags="light")

    self.app.after(0, self.change_light)

def change_light(self):
    i = self.ligth_canvas.find_withtag("light")

    if self.light_on:
        self.ligth_canvas.itemconfig(i, fill="blue")
        self.light_on = False
        print "on"
    else:
        self.ligth_canvas.itemconfig(i, fill="red")
        self.light_on = True
        print "of"

    self.app.after(5000, self.change_light)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:06:03+00:00Added an answer on June 15, 2026 at 11:06 am

    The problem you are having is that you are creating the canvas on every iteration, and packing it below all of the other canvases. When you say the object color isn’t changing, that’s because you are observing the first canvas you created; the color is changing for the most recently created canvas but it is off screen.

    Change your code to create a single canvas and your code will otherwise work just fine. For example:

    import Tkinter as tk
    
    class App(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
            self.frame_Light = tk.Frame(self, background="bisque")
            self.frame_Light.pack(side="top", fill="both", expand=True)
            self.light_on = True
            self.canvas = tk.Canvas(self.frame_Light)
            self.canvas.create_oval(10, 10, 30, 30, fill="yellow", tags="light")
            self.canvas.pack(side="top", fill="both", expand=True)
            self.draw_light()
    
        def draw_light(self):
    
            if self.light_on:
                self.canvas.itemconfig("light", fill="blue")
                self.light_on = False
                print "on"
            else:
                self.canvas.itemconfig("light", fill="red")
                self.light_on = True
                print "of"
    
            self.after(1000, self.draw_light)
    
    app = App()
    app.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Custom View, I draw multiple filled Arc s like this: canvas.drawArc(oval, startAngle,
I draw an oval on a canvas: RectF f = new RectF(-r, -r, r,
There doesnt seem to be a native function to draw an oval-like shape. Also
I draw picture in canvas in place where I click. This is code: public
I draw an arc using onDraw(canvas) : @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
I draw an oval g.fillOval (0, 0, 100, 40) ; How to turn it
public void paintComponent(final Graphics g) { super.paintComponent(g); g.setColor(Color.red); g.drawOval(x,y,width,height); g.fillOval(x,y,width,height); } This method draws
Here's my canvas class extending JPanel : package start; import java.awt.Color; import java.awt.Graphics; import
In my app i am able to draw something on canvas within on touch
I cannot get this oval to draw on the JFrame. static JFrame frame =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.