Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tkinter problem making 30 degree angle multiple times

I have a problem https://prnt.sc/1znuffv with tkinter, I need it to reach from 0 to 180 degrees with making "checkpoint" every 30 degrees, I got help on this site to successfully done to reach 0-180 and back but cannot make it 30 by 30.

import tkinter as tk
root = tk.Tk()
root.geometry("800x800")
root.resizable(0, 0)

s = 0
def menjajKanvas(arc):
global s
if s < 180:
    s+=1
    c.itemconfig(arc,extent=s,fill="red")
    root.after(10,menjajKanvas,arc)
else:
    shrink_arc(arc)
def shrink_arc(arc):
global s
if s >= 0:
    s-=1
    c.itemconfig(arc,extent=s,fill="red")
    root.after(10,shrink_arc,arc)
else:
    root.after(10,menjajKanvas,arc)

c = tk.Canvas(root, height=250, width=300, bg="blue")
c.pack()
arc = c.create_arc(10,50,240,210,
               extent=150,
               outline="red",
               fill='red',
               tags=("arc",))
menjajKanvas(arc)
root.mainloop()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could use a variable delay in your function calls issued via tk.after:

something like this:

import tkinter as tk


def menjajKanvas(arc):
    global s
    if s < 180:
        s += 1
        c.itemconfig(arc,extent=s,fill="red")
        delay = 10 if s % 30 else 1000
        root.after(delay, menjajKanvas, arc)
    else:
        root.after(1000, shrink_arc(arc))


def shrink_arc(arc):
    global s
    if s >= 0:
        s -= 1
        c.itemconfig(arc,extent=s,fill="red")
        delay = 10 if s % 30 else 1000
        root.after(delay, shrink_arc, arc)
    else:
        root.after(1000, menjajKanvas(arc))


if __name__ == '__main__':

    root = tk.Tk()
    root.geometry("800x800")
    root.resizable(0, 0)

    s = 0

    c = tk.Canvas(root, height=250, width=300, bg="blue")
    c.pack()
    
    arc = c.create_arc(
        10, 50, 240, 210,
        extent=150,
        outline="red",
        fill='red',
        tags=("arc",))
    
    menjajKanvas(arc)
    
    root.mainloop()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading