Delaying parts of text being inserted into Scroll Text Box (scrolledtext)

Asked
Active3 hr before
Viewed126 times

4 Answers

partsinsertedscrollscrolledtext
90%

The frame which surrounds the text and scroll bar widgets,,The scroll bar widget

Example_snippet/controller/utility/_parts.js/ ScrolledText. . .
ScrolledText
Step 2 continued with tkinter.Text. . .
tkinter.Text
load more v
88%

To help illustrate this point, this script binds the Escape key press to fetch and print the entire contents of the Text widget it embeds:,In Chapter 9, we'll put these two widgets to use to implement text editors (PyEdit), paint programs (PyDraw), clock GUIs (PyClock), and photo slideshows (PyView), For the purposes of this tour chapter, though, let's start out using these widgets in simpler ways

Example_snippet/controller/utility/_inserted.js/ # a simple text or file viewer. . .
# a simple text or file viewer component

print 'PP2E scrolledtext'
from Tkinter
import *

class ScrolledText(Frame):
   def __init__(self, parent = None, text = '', file = None):
   Frame.__init__(self, parent)
self.pack(expand = YES, fill = BOTH) # make me expandable
self.makewidgets()
self.settext(text, file)
def makewidgets(self):
   sbar = Scrollbar(self)
text = Text(self, relief = SUNKEN)
sbar.config(command = text.yview) # xlink sbar and text
text.config(yscrollcommand = sbar.set) # move one moves other
sbar.pack(side = RIGHT, fill = Y) # pack first = clip last
text.pack(side = LEFT, expand = YES, fill = BOTH) # text clipped first
self.text = text
def settext(self, text = '', file = None):
   if file:
   text = open(file, 'r').read()
self.text.delete('1.0', END) # delete current text
self.text.insert('1.0', text) # add at line 1, col 0
self.text.mark_set(INSERT, '1.0') # set insert cursor
self.text.focus() # save user a click
def gettext(self): # returns a string
return self.text.get('1.0', END + '-1c') # first through last

if __name__ == '__main__':
   root = Tk()
try:
st = ScrolledText(file = sys.argv[1]) # filename on cmdline
except IndexError:
   st = ScrolledText(text = 'Words
      go here ') # or not: 2 lines
      def show(event): print repr(st.gettext()) # show as raw string root.bind('', show) # esc = dump text root.mainloop()
load more v
72%

The ScrolledText widget uses a Frame widget inserted between the container and the Text widget to hold the Scrollbar widget,,Summary: in this tutorial, you’ll learn how to use the Tkinter ScrolledText widget that consists of a Text widget and vertical Scrollbar widget

Example_snippet/controller/utility/_inserted.js/ .wp-block-code { border: 0; . . .
.wp - block - code {
      border: 0;
      padding: 0;
   }

   .wp - block - code > div {
      overflow: auto;
   }

   .shcb - language {
      border: 0;
      clip: rect(1 px, 1 px, 1 px, 1 px); -
      webkit - clip - path: inset(50 % );
      clip - path: inset(50 % );
      height: 1 px;
      margin: -1 px;
      overflow: hidden;
      padding: 0;
      position: absolute;
      width: 1 px;
      word - wrap: normal;
      word - break: normal;
   }

   .hljs {
      box - sizing: border - box;
   }

   .hljs.shcb - code - table {
      display: table;
      width: 100 % ;
   }

   .hljs.shcb - code - table > .shcb - loc {
      color: inherit;
      display: table - row;
      width: 100 % ;
   }

   .hljs.shcb - code - table.shcb - loc > span {
      display: table - cell;
   }

   .wp - block - code code.hljs: not(.shcb - wrap - lines) {
      white - space: pre;
   }

   .wp - block - code code.hljs.shcb - wrap - lines {
      white - space: pre - wrap;
   }

   .hljs.shcb - line - numbers {
      border - spacing: 0;
      counter - reset: line;
   }

   .hljs.shcb - line - numbers > .shcb - loc {
      counter - increment: line;
   }

   .hljs.shcb - line - numbers.shcb - loc > span {
      padding - left: 0.75 em;
   }

   .hljs.shcb - line - numbers.shcb - loc::before {
      border - right: 1 px solid #ddd;
      content: counter(line);
      display: table - cell;
      padding: 0 0.75 em;
      text - align: right; -
      webkit - user - select: none; -
      moz - user - select: none; -
      ms - user - select: none;
      user - select: none;
      white - space: nowrap;
      width: 1 % ;
   }
import tkinter as tk
from tkinter.scrolledtext
import ScrolledText

root = tk.Tk()
root.title("ScrolledText Widget")

st = ScrolledText(root, width = 50, height = 10)
st.pack(fill = tk.BOTH, side = tk.LEFT, expand = True)

root.mainloop() Code language: JavaScript(javascript)
load more v
65%

I want to delay parts of the text being inserted into the text box, As in, one line of text is insert, there a 3 second delay, the next line of text is inserted and so on

Example_snippet/controller/utility/_inserted.js/ def insertText(): global p. . .
def insertText():
   global previousDelay
previousDelay = 0
delayedInsert('This line should be inserted first.\n', 0)
delayedInsert('This line should be inserted after a 1 second delay.\n', 1)
delayedInsert('This line should be inserted after a 3 second delay.\n', 3)
delayedInsert('This line should be inserted after a 3 second delay.\n', 3)

def delayedInsert(text, delay):
   global previousDelay
trialGUI.after((delay + previousDelay) * 1000, lambda: trialBox.insert(tk.INSERT, text))
previousDelay += delay