I can read one line at a time, from an input box, and display it in a new box, but I need to advance to the next line of code.
Here are the text boxes in the GUI
self.sourcecode = Text(master, height=8, width=30)
self.sourcecode.grid(row=1, column=1, sticky=W)
self.nextline = Button(master, text="Next Line", fg="orange", command=lambda:[self.nextLine(self.intcount), self.lexicalResult()])
self.nextline.grid(row=12, column=1, sticky=E)
self.lexicalresult = Text(master, height=8, width=30)
self.lexicalresult.grid(row=1, column=3, sticky=W)
These are my functions to copy from one box, to the other (output would insert()
into the lexicalResult()
function)
def nextLine (self, intcount):
print("Reading from source")
self.linenumber.delete('1.0', END)
self.intcount = self.intcount + 1
self.linenumber.insert('0.0', self.intcount)
self.retrieve_input()
def retrieve_input(self):
lines = self.sourcecode.get('1.0', '2.0') #I need to take this and move to the next line but i am new to python and don't know what functions there are or their arguments
self.lexicalresult.insert('1.0', lines)
def lexicalResult (self):
print("Printing to result")
You can read a single line of text by using the "lineend" modifier on an index. For example, to get all of line 1 you could use something like this:
That will get everything on the line except the trailing newline. If you want the trailing newline, get just one character more:
To delete an entire line you could use the very same indexes and pass them to the
delete
method.As a more general purpose rule, given any index, to compute the beginning of the next line you can use something like this:
The
index
method converts an index into it's canonical form. The "lineend" modifier changes the index to the end of the line, and+1c
moves it one character further.