''' Tk_Text_ticker102.py
using Tkinter to create a marquee/ticker
uses a display width of 20 characters
not superbly smooth but good enough to read
tested with Python27 and Python33  by  vegaseat  04oct2013
'''

import time
try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()

# width --> width in chars, height --> lines of text
text_width = 20
text = tk.Text(root, width=text_width, height=1, bg='yellow')
text.pack()

# use a proportional font to handle spaces correctly
text.config(font=('courier', 48, 'bold'))

s1 = "We don't really care why the chicken crossed the road.  "
s2 = "We just want to know if the chicken is on our side of the "
s3 = "road or not. The chicken is either for us or against us.  "
s4 = "There is no middle ground here.  (George W. Bush)"
# pad front and end of text with spaces
s5 = ' ' * text_width
# concatenate it all
s = s5 + s1 + s2 + s3 + s4 + s5

for k in range(len(s)):
    # use string slicing to do the trick
    ticker_text = s[k:k+text_width]
    text.insert("1.1", ticker_text)
    root.update()
    # delay by 0.22 seconds
    time.sleep(0.22)

root.mainloop()

Hello ,
Thank you for this ticker example , It's realy a useful result of the Tkinter module .

This is what I got from theantonio.neal.39's post by tinkering:

from tkinter import *

def move():   
    if message.winfo_x() + message.move >= message.x_limit or message.winfo_x() + message.move < 0:
        message.move = -message.move
    message.place(x=message.winfo_x() + message.move)
    message.after(message.delay, move)

gui = Tk()
gui.geometry('8000x100+1+600')                 
gui.title('ALERTS')
gui.config (bg = 'blue')                       
message = Label(gui, text = 'this is a demo')
message.config (fg = 'white',bg = 'blue', font=('times','60'))
message.x_limit = 2000
message.move = 2
message.delay = 5
message.place(x=1)
message.after(10, move)
gui.mainloop()

Edited 3 Years Ago by pyTony

Hello pyTony , i don't understand you about my last reply . This call to tkinter works only with python3.x ?

Using the Tkinter canvas for the ticker makes it run a little smoother ...

''' Tk_Canvas_ticker1.py
using a Tkinter canvas to create a marquee/ticker via
canvas.create_text(x, y, anchor='nw', text=s, font=font)
canvas.move(object, x_increment, y_increment)
tested with Python27 and Python33  by  vegaseat  04oct2013
'''

import time
try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()

canvas = tk.Canvas(root, height=80, width=600, bg="yellow")
canvas.pack()

font = ('courier', 48, 'bold')

text_width = 15
s1 = "We don't really care why the chicken crossed the road.  "
s2 = "We just want to know if the chicken is on our side of the "
s3 = "road or not. The chicken is either for us or against us.  "
s4 = "There is no middle ground here.  (George W. Bush)"
# pad front and end of text with spaces
s5 = ' ' * text_width
# concatenate it all
s = s5 + s1 + s2 + s3 + s4 + s5

x = 1
y = 2
text = canvas.create_text(x, y, anchor='nw', text=s, font=font)

dx = 1
dy = 0  # use horizontal movement only
# the pixel value depends on dx, font and length of text
pixels = 9000
for p in range(pixels):
    # move text object by increments dx, dy
    # -dx --> right to left
    canvas.move(text, -dx, dy)
    canvas.update()
    # shorter delay --> faster movement
    time.sleep(0.005)
    #print(k)  # test, helps with pixel value

root.mainloop()

Edited 3 Years Ago by vegaseat

Hello ,
The second example works better , It just stoping a small periods sometimes . My question is how can i put the Tkinter window on the top of the sceen ?

To put the tkinter window on top of your screen you can use ...

x = 0
y = 0
# set UpperLeftCorner x, y position of root
root.geometry("+%d+%d" % (x, y))

Is there any good way to scale the pixels variable by the the input? Like is there a way to expresses pixels as a function of the text length, the font, and the fount size?

Once the text item is created, you can obtain a bounding box with canvas.bbox(item=text), or something similar.

Edited 1 Year Ago by Gribouillis

Hello,

How to make the canvas moves continuously without stopping?

BR,

Edited 9 Months Ago by Mohamed_65

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.