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 :
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()