As @berak already said you have mistakes in code.
Here full working code for all users
import cv2
import numpy as np
# --- functions ---
def showcolour(value):
print(value)
# --- main ---
# create black image at start
img = np.zeros((300,512,3), np.uint8)
# create window with name `img`
cv2.namedWindow('img')
# add trackbars to window `img` - and assign function `showcolour` to trackbars
cv2.createTrackbar('b', 'img', 0, 255, showcolour)
cv2.createTrackbar('g', 'img', 0, 255, showcolour)
cv2.createTrackbar('r', 'img', 0, 255, showcolour)
# run main loop
while True:
# get values from trackbars in window `img`
b = cv2.getTrackbarPos('b', 'img')
g = cv2.getTrackbarPos('g', 'img')
r = cv2.getTrackbarPos('r', 'img')
# replace all pixels with new value
img[:] = [b, g, r]
# display new image in window `img`
cv2.imshow('img', img)
# check if pressed key (wait for key 1ms)
k = cv2.waitKey(1) & 0xFF
# exit when pressed `ESC
if k == 27:
break
# destroy window `img`
cv2.destroyWindow('img')
# OR: destroy all windows
#cv2.destroyAllWindows()
Screenshot: Linux Mint 20 (based on Ubuntu 20.04)