[英]How to reinitialize text widget in Tkinter?
I am trying to return the search result of the user in the GUI itself. 我试图在GUI本身中返回用户的搜索结果。 This is the following code which I am using
这是我正在使用的以下代码
def printResult(searchResult):
global resultsFrame
text = Text(resultsFrame)
for i in searchResult:
text.insert(END,i+'\n')
text.pack(side=TOP)
where searchResult is a list which has all the statements to be printed on the screen and this is how I declared resultsFrame in the code (before root.mainloop()) I am using global so that it makes changes to the existing frame but it rather adds another frame below it. 其中searchResult是一个列表,其中包含所有要在屏幕上打印的语句,这就是我在代码中声明resultFrame的方式(在root.mainloop()之前),我正在使用global,以便对现有框架进行更改,但是在其下方添加另一个框架。 How to make changes in the already existing text widget?
如何在现有的文本小部件中进行更改?
resultsFrame = Frame(root)
resultsFrame.pack(side=TOP)
For reference here is an image of the GUI: 作为参考,这里是GUI的图像:
EDIT : Issue Solved 编辑: 问题已解决
I declared the frame outside the function 我在函数外部声明了框架
resultsFrame = Frame(root)
resultsFrame.pack(side=TOP)
text = Text(resultsFrame)
def printResult(searchResult):
global resultsFrame
global text
text.delete("1.0",END)
for i in searchResult:
text.insert(END,str(i)+'\n')
text.pack(side=TOP)
Try this: 尝试这个:
global resultsFrame
text = Text(resultsFrame)
def printResult(searchResult):
for i in searchResult:
text.insert(END,i+'\n')
...
text.pack(side=TOP)
This should solve your issue. 这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.