Reputation: 6944
i am new to Python + tkinter
I am trying to enter values into a text widget using FOR loop
The problem is, text widget not showing anything during For loop execution. When for loop finishes, it shows all values.
How can I show inserted values during for loop.
See last line of code
for item in liList:
listDict = {}
# get a tag href
listATag = item.find_all("a", attrs={"class": "product-image"})[0]
listATagHref = listATag['href']
listDict["purchaseLink"] = listATagHref
imgPageRequest = requests.get(listATagHref)
imgPageData = imgPageRequest.text
imgPageSoup = BeautifulSoup(imgPageData, 'lxml')
try:
productImgDiv = imgPageSoup.find_all('div', attrs={"class": "product-image"})[0]
imgATag = productImgDiv.find_all('a')[0]['href']
largeThumbFileName = (imgATag.split('/')[-1])
tempImgNameList.append(largeThumbFileName)
print(listATagHref)
textBox.insert(END,listATagHref+'\n')
etc...
Upvotes: 0
Views: 1786
Reputation: 11
aside from updating the window, or the text widget you can change the first argument of your textbox from END to INSERT.
import tkinter as tk
# inside the try block change the first argument to INSERT
textBox.insert(tk.INSERT,listATagHref+'\n')
Upvotes: 0
Reputation: 1857
You need to call update
on the widget you are adding new data to, for it to refresh and show the new values after each iteration. This is as the Tk mainloop
will normally catch the new information on your widget and update it, but when you are in a loop such as this, it cannot check until after the loop is finished.
If root
is what you define to be Tk()
, then you can call root.update()
, or on the actual widget itself. This would go at the end of your for
loop.
Upvotes: 3