I can’t change the title of my tkinter window. It always says “tk”.
I’m on debian 12 (bookworm) running python3.
If I use “ttk” it works. But ttk has no support for “Canvas”. There must be a way to set the title in plain tk.
Here’s my code:
import tkinter as tk
from PIL import Image, ImageTk
import cv2
window = tk.Tk()
window.geometry("1600x900")
window.title=("LABCAM")
def show_frame():
global image_id
ret, frame = cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
img = img.resize((1400, 900), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image=img)
canvas.photo = photo
if image_id:
canvas.itemconfig(image_id, image=photo)
else:
image_id = canvas.create_image((0,0), image=photo, anchor="nw")
canvas.configure(width=photo.width(), height=photo.height())
window.after(20, show_frame)
image_id = None
cap = cv2.VideoCapture(0)
frame_cam = tk.Frame(master=window, width=1400, height=900, bg="red")
frame_ctrl = tk.Frame(master=window, width=200, height=900, bg="blue")
frame_cam.pack(side=tk.LEFT)
frame_ctrl.pack(side=tk.RIGHT)
canvas = tk.Canvas(frame_cam)
canvas.pack(fill="both", expand=True)
show_frame()
window.mainloop()
cap.release()