0

I am trying to make Tkinter Canvas text of length x continuously scroll across a finite area less than x. I have multiple canvastext objects with different text. If I print(newtext) it shows the scroll i want but it does not display during the running of the program. I tried with a while True: loop and it never displayed the canvas at all. Any help would be appreciated.

 text='really long text string that i want to scroll 15 characters at a time'

 canvastext=canvas.create_text(1,1,text=scrolltext(text),
 tag=(calmotag,booktag,'texttag'),width=20)

def scrolltext(text):
     textlength=15
     shorttext=tkinter.StringVar() 
     shorttext.set(text.get()[0:14])
     itemtext=text.get()
     if len(itemtext)>textlength:

         newindex=0
         endindex=newindex+14
         while endindex<len(itemtext)+2:
             oldtext=shorttext.get()
             oldindex=itemtext.index(oldtext)
             newindex=oldindex+1
             endindex=newindex+14
             newtext=itemtext[newindex:endindex]
             shorttext.set(newtext)
             root.update_idletasks()
             root.after(1000)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Don't do your animation with a `while` loop in tkinter. It's an antipattern. See http://stackoverflow.com/a/11505034/7432 – Bryan Oakley May 15 '16 at 13:26
  • Thanks Bryan for the link. It works perfectly. I tried similar but with a for or while loop but was not getting the output desired. As soon as I removed the loops and adjusted the code to change the text each scrolltext() callback it worked. – Sean Gallagher May 18 '16 at 03:16

0 Answers0