Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

News Scrolling Text in Python

I want to write a small program that displays auto-scrolling news ticker text from left to right (with Tkinter?),or at least some GUI.

The text should come from a text .txt file.

I am still a beginner in Python and can't really grasp how to do this? Like how to control the timings from each line to show up etc?

Would a loop calling each line be the right way to do this?

Or how would you approach this? All help/links will be very appreciated

like image 965
Welsh King Avatar asked Dec 15 '12 20:12

Welsh King


1 Answers

Here's a program using Tkinter to scroll text in a box. See 1 and 2 regarding options for label(); see 3 about the after() method.

import Tkinter as tk

root = tk.Tk()
deli = 100           # milliseconds of delay per character
svar = tk.StringVar()
labl = tk.Label(root, textvariable=svar, height=10 )

def shif():
    shif.msg = shif.msg[1:] + shif.msg[0]
    svar.set(shif.msg)
    root.after(deli, shif)

shif.msg = ' Is this an alert, or what? '
shif()
labl.pack()
root.mainloop()
like image 155
James Waldby - jwpat7 Avatar answered Oct 03 '22 23:10

James Waldby - jwpat7