Search code examples
pythonscrollnews-ticker

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


Solution

  • 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 (not seconds)
    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()