[Python] tk canvas telepromter text transparency problems

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a fullscreen window with a fullscreen canvas. First I place a fullscreen background image in this canvas.

    canvas = tk.Canvas(window, bg="white", bd=0)
    canvas.pack(fill=tk.BOTH, expand=True)
    canvas.update()

    image = Image.open('bild.jpg')
    newimage = image.resize((canvas.winfo_width(),canvas.winfo_height()),Image.LANCZOS)
    photo = ImageTk.PhotoImage(newimage, master=canvas)
    canvas.create_image(0, 0, anchor="nw", image=photo)
    canvas.update()


    Then I place a headline text on the top right and below this a longer text. The text is much longer than the screen height.

    rectangle_width = int(canvas.winfo_width() * 0.45)
    rectangle_x = canvas.winfo_width() - rectangle_width

    headblock = canvas.create_text(
    rectangle_x+10, 10,
    anchor='nw',
    text=headline,
    font=('Helvetica', 18, 'bold'),
    fill='black',
    width=rectangle_width - 20
    )
    x1, y1, x2, y2 = canvas.bbox(headblock)
    textblock = canvas.create_text(
    rectangle_x+10, y2+10,
    anchor='nw',
    text=fulltext,
    font=('Helvetica', 14, 'normal'),
    fill='black',
    width=rectangle_width - 20
    )
    canvas.update()


    Now I wan't to animate the long text, like a telepromter, moving slowly upwards, so that viewers can read the full text. This works fine with canvas.move()

    def animate():
    canvas.move(textblock, 0, -1)
    x1, y1, x2, y2 = canvas.bbox(textblock)
    if y2 > canvas.winfo_height():
    window.after(60, animate)


    But while the textblock is moving up it is shown behind the headline. The problem is the background image. That should always be visible. If I place headline and text in different objects, labels, canvas, whatever, they are not transparent anymore.

    Has anyone a good idea, how move the only the long text, while the image is always visible and the headline stays static?

    Continue reading...

Compartilhe esta Página