Question

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

Was it helpful?

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
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()

OTHER TIPS

I've used two different libraries with Python so far:

PyQt - wraps Qt and is in my opinion a nice Gui library but then I haven't used any absolute positioning like you want to, but I can't see how that should be any major problem.

PyGame - As you've guessed it's main purpose is games but what you want to do should be simple to do.

Go through a couple of tutorials with the library of your choice and your task shouldn't be any problem at all. For what you want to do I think that PyGame would be the easiest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top