【发布时间】:2019-09-20 17:52:55
【问题描述】:
我可以从输入框中一次读取一行,并将其显示在新框中,但我需要前进到下一行代码。
这是 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)
这些是我从一个盒子复制到另一个盒子的函数(输出将 insert() 到 lexicalResult() 函数中)
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")
【问题讨论】:
-
运行该代码时会发生什么?它有什么作用,它与您的预期有何不同?
-
@BryanOakley 如果我在源代码框中输入两行源代码,它会在结果框的同一行输出两行,中间只有一个空格。我希望它读取一行,然后打印一行,然后重复
-
使用explain-tkinter-text-search-method 或获取整个
sourcecode并执行split('\n') -
Split 非常感谢!
标签: python python-3.x tkinter tkinter.text