Hi, I have a GUI written with wxPython that contains a form. When the button is clicked, a script is executed to cycle through a specified directory and resize the images to a 50% size (the image manipulation is done with PIL). I used to run this script via the console/terminal, and during the image resizing and such, it would print progress to the screen. This whole process worked fine just running plain from the console, but I've rigged it to print the output to a multi-line text ctrl in the GUI now instead. When I run the script, everything is fine and works, EXCEPT that the GUI freezes during the processing of the images. It will finish the tasks correctly, it just freezes the GUI while doing it. Does anyone know what's happening?

(Yes, the processing is fairly intensive, but when running in a console, messages were still able to be printed during it. It's only now that I've moved the output to a text ctrl on the GUI that I have issues with it.)

Well python only does one thing at a time so perhaps while the images are being done it dosent do the GUI. A way around this is to use the thread module.

Threading is useful if you want two things to be able to happen at once.

Ah, I didn't think of that. I'll take a look into threading (I've never used it before) to see if it helps. Thanks!

Just make sure that both things you want are methods. I think you will want to do something like:

import wx #if using wxPython
import thread

class Frame(wx.Frame):
    #all the code stuff

def image(path):
    #image stuff

# then you go:
app = wx.App(0)
f = Frame()
thread.start_new_thread(app.MainLoop,())
thread.start_new_thread(image,(path))
commented: Threading idea/example was a HUGE help! +2

YES! Thanks for that threading code, because I have it working perfectly now! Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.