Multiline textbox
def gui_init():
global textbox_my_textbox
#----- LIVE PROCESSING BOX -----
MonospaceFont = font.Font(family="Courier", size=10)
textbox_my_textbox = tk.Text(
root,
bg="white",
font=MonospaceFont,
wrap = "word",
height=8,
width=50
)
textbox_my_textbox.pack(padx=10, pady=10)
textbox_my_textbox.place(x=10, y=310)
textbox_my_textbox.insert(tk.END, "Loading...\n")
Overwrite all text
NewText = "Hello\nNew content"
textbox_my_textbox.delete("1.0", tk.END)
textbox_my_textbox.insert("1.0", NewText)
Multiline textbox that auto removes top line once full example
#*******************************************************
#*******************************************************
#********** ADD A LINE TO LIVE PROCESSING BOX **********
#*******************************************************
#*******************************************************
def textbox_my_textbox_add_line (new_line):
global textbox_my_textbox
#Get current line count
LineCount = int(textbox_my_textbox.index("end-1c").split('.')[0])
#Delete top line if we're over # lines
if LineCount >= 7:
textbox_my_textbox.delete("1.0", "2.0") #Delete the first line (from line 1, char 0 to line 2, char 0)
#Add a timestamp to the start of the new line
#time_stamp = datetime.now().strftime("%H:%M:%S")
#new_line = f"{time_stamp} {new_line}"
#Add the new line to the textbox
textbox_my_textbox.insert(tk.END, new_line + "\n")
gui_update()
