I have a slider and spinbox connected to the same DoubleVar p1. I'm trying to draw an arc that changes position on the canvas as p1 changes.
I tried to draw the arc with arc = myCanvas.create_arc using p1.get() in the parameters, but the arc only draws with p1's initial value of 0, and does not update as the value changes.
Here is an example
import tkinter as tk
from tkinter import ttk
import math
root = tk.Tk()
root.title('Lens')
root.configure(background='#ececec')
root.resizable(False, False)
h = 600
w = 800
myCanvas = tk.Canvas(root, bg="#ececec", height=h, width=w, highlightthickness=0)
y = h/2
x = w/3
r=200
p1 = tk.DoubleVar()
slider1= ttk.Scale(
root,
from_=0,
to=w/2,
orient='horizontal',
variable=p1
)
slider1.pack(ipadx=50, padx=0, anchor=tk.NW, side=tk.LEFT)
spin1 = ttk.Spinbox(
root,
textvariable=p1,
wrap=True,
width=5,
from_=0,
to=w/2,
increment=.01
)
spin1.pack(anchor=tk.NW, side=tk.LEFT)
x1=p1.get()
# lens shape
arc11 = myCanvas.create_arc(x1-1/8*r, y+r*math.sqrt(7)/4, x1+7/8*r, y-r*math.sqrt(7)/4, start=90+180/math.pi*math.atan(3/math.sqrt(7)), extent=2*180/math.pi*math.atan(math.sqrt(7)/3), style=tk.ARC)
arc12 = myCanvas.create_arc(x1-7/8*r, y+r*math.sqrt(7)/4, x1+1/8*r, y-r*math.sqrt(7)/4, start=90-180/math.pi*math.atan(3/math.sqrt(7)), extent=-2*180/math.pi*math.atan(math.sqrt(7)/3), style=tk.ARC)
myCanvas.pack()
root.mainloop()