0
votes

I want to have a horizontally scrollable text window in tkinter. The window is updated every now and then and new piece of text is added, that shifts the already existing text to the right. The issue is when the text reaches the end of the window, at which time it doesn't continue to travel to the right but instead jumps to the new line below. Therefore the text becomes scrollable vertically and not horizontally. Here' the code:

from Tkinter import *

root = Tk()
root.title("PCB Tester ver 0.1")
root.geometry("1000x1000")

data1 = Text(root,height=1,width=20)

scrollbar1=Scrollbar(root, orient=HORIZONTAL)   
scrollbar1.config(command=data1.xview)
scrollbar1.grid(row=1,column=0,sticky=EW)

data1.config(xscrollcommand=scrollbar1.set)
data1.grid(row=0,column=0,sticky = W)

def addText():
    data1.insert('0.0', 'Sample Text')
    root.after(1000, addText)

addText()
root.mainloop()

Is there any way to make the text continue to be pushed to the right so I can use a horizontal scroll?

1

1 Answers

1
votes

You should prevent wrapping, when you define the Text widget:

from Tkinter import *

root = Tk()
root.title("PCB Tester ver 0.1")
root.geometry("1000x1000")

data1 = Text(root,height=1,width=20, wrap="none")

scrollbar1=Scrollbar(root, orient=HORIZONTAL)   
scrollbar1.config(command=data1.xview)
scrollbar1.grid(row=1,column=0,sticky=EW)

data1.config(xscrollcommand=scrollbar1.set)
data1.grid(row=0,column=0,sticky = W)

def addText():
    data1.insert('1.0', 'Sample Text')
    root.after(1000, addText)

addText()
root.mainloop()