Hi everybody!
I wrote for my company one little test application: Frame , Pmw.NoteBook and few buttons.
and one main button 'Start' under NoteBook which starts process depend on name of Pmw.NoteBook...
everything is fine , the problem is each of the processes run ~10 min and all this time: button 'Start' is still pressed; GUI not responsable at all, so I can't go to another Tab and start another process... :(
I guess it multithreading issue ... Does somebody has little example to start two processes from one button?
Will be very appreciated for any suggestion.
Thanks,
Slava.

yes you need to make it multi-threaded. Everytime the user clicks on the button it can spawn a new thread which does the work and the button is free for input. i think this code should help you

from Tkinter import *
import threading
import time

class process(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        print 'hello'
        time.sleep(60)
        print 'bye'        

#The class process derives from threading.Thread. whenver we say process.start it spawns #a new thread and calls it's 'run' method
def startThread():
    process().start()
    
root = Tk()
frame = Frame(root)
frame.pack()

#when user clicks button it calls 'startThread' command
but = Button(frame,text='start',command=startThread)
but.pack()

text = Text(frame)
text.pack()

root.mainloop()

you'll see that each thread sleeps for a minute but the input button doesn't wait for the output and is ready to take the next input. Once each thread finishes it prints the 'bye' message.

I'm fairly new to multi-threading myself so if you find any issues with this let me know or any doubts.

Thanks. Agni, sorry was out...
hm make sense .... so how I understand class "process" should communicate with procedure invoked from my "Start" button? This is the question for me: should class "process" contain my whole program or how ?
Thanks!

Does anybody else can suggest me how to tight my Start button with "class process(threading.Thread):" ?

Thanks in advance!
Slava

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.