I have a small function to create scrolling text within a tkinter canvas. It works well except I cannot drag the containing window. I suspect this is because the time period is quite short. Any thoughts welcomed.
In the code below self.widget is the canvas and self.text is the canvas object which contains text.
def scroll_text(self):
if self.current_ticker_text == "":
return
self.view.root.update() # refresh wondow to ensure we get proper widget width else it will return a '1'
self.text = self.widget.create_text(self.widget.winfo_width() - 200, 10, anchor='nw',
text=self.current_ticker_text)
self._scrolling()
def _scrolling(self):
if self.text is None:
return
self.widget.move(self.text, -1, 0)
self.widget.update()
ticker_timer = self.view.root.after(15, self._scrolling)
bbox_result = self.widget.bbox(self.text)
if bbox_result is not None:
if bbox_result[2] < -5:
self.scroll_text()
self.view.root.after_cancel(ticker_timer)
I am expecting to be able to drag the window around the screen and still have the text scrolling.
I moved the line self.widget.update() and placed it after the self.view.root.after_cancel(ticker_timer) line. All works now