I was wondering how someone would go about making a scrolling ticker or marquee using Tkinter in such a way that allows you to easily add on text and remove.. kinda like a news scroller on the bottom of the tv?
# using Tkinter to create a marquee/ticker
# uses a display width of 20 characters
# not superly smooth but good enough to read
import Tkinter as tk
root = tk.Tk()
# width=width chars, height=lines text
text = tk.Text(root, width=20, height=1, bg='yellow')
# use a proportional font to handle spaces correctly
text.config(font=('courier', 24, 'bold'))
s1 = "I was wondering how someone would go about making a scrolling ticker"
# pad front and end with 20 spaces
s2 = ' ' * 20
s = s2 + s1 + s2
for k in range(len(s)):
# use string slicing to do the trick
ticker_text = s[k:k+20]
# delay by 0.15 seconds
thats brilliant, my method involved updating a label with the text all shuffled 1 place to the left each time.
I'm having some trouble understand your slicing method. I can't quite work out what the +20 is for, is that just a number 'that works' or is it to compensate for the 20 spaces padding the text, or is it for the width of the text wiget.. or are all those numbers infact linked.
Yea i'm using the text version for now, for simplicity and so i can get the rest of the program running, but i'll probably try to work out a canvas method later. i'll post it if it works, cause i had a hard time finding anything on google