According to your code, you can move "TrackBars" window, but can't move "my WEBcam" window, because you used fixed coordinate values in the while loop:
while True:
...
cv2.moveWindow('my WEBcam',0,0)
...
If you want to move the window, just comment out the line:
while True:
...
# cv2.moveWindow('my WEBcam',0,0)
...
In addition, to make the "TrackBars" window on top of the "my WEBcam" window, you need to add one more line:
cv2.namedWindow("my WEBcam")
cv2.namedWindow("TrackBars")
I've modified the code to test the "TrackBars" window:
import cv2
print(cv2.__version__)
***=cv2.VideoCapture(0)
WIDTH=640
HEIGHT=480
***.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
***.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)
***.set(cv2.CAP_PROP_FPS, 30)
***.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
xPos = WIDTH//2
yPos = HEIGHT//2
radius = 25
windowX = 0
def setX(x):
global xPos
xPos = x
def setY(y):
global yPos
yPos = y
def setRadius(r):
global radius
radius = r
def setWindowX(x):
global windowX
windowX = x
cv2.namedWindow("my WEBcam")
cv2.namedWindow("TrackBars")
cv2.resizeWindow("TrackBars", 250, 200)
cv2.moveWindow("TrackBars", windowX, 400)
cv2.createTrackbar("xPos", "TrackBars", WIDTH//2, WIDTH, setX)
cv2.createTrackbar("yPos", "TrackBars", HEIGHT//2, HEIGHT, setY)
cv2.createTrackbar("radius", "TrackBars", 25, HEIGHT//2, setRadius)
# Test moveWindow
cv2.createTrackbar("moveWindow", "TrackBars", 25, HEIGHT//2, setWindowX)
while True:
ignore, frame = ***.read()
cv2.circle(frame, (xPos, yPos), radius, (0, 255, 0), 2)
cv2.imshow('my WEBcam', frame)
cv2.moveWindow('my WEBcam',0,0)
cv2.moveWindow("TrackBars", windowX, 400)
if cv2.waitKey(1) == ord('q'):
break
***.release()
macOS
Windows