0

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...

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.