How can I write threading with tkinter?

34 Views Asked by At

I try to develop a program with tkinter. However I need a threading due to some functions in my program.

I'm calling a function when I clicked the button to send mail to the releated e-posta addresses. But, threading doesn't work.(Meanwhile there is no error.) Also in the button function after mail operations, a window is opening.

Here is the my code!

def adminControl():
    global adcWin, usmaEnt, uspsEnt
    intW.introWin.destroy()
    iWidth = int(intz.width/2.6)
    iHeight = int(intz.height/3.5)
    iwL = int((intz.width-iWidth)/2)
    ihL = int((intz.height-iHeight)/2)    
    adcWin = tk.Tk()
    adcWin.title("ARCEN - Admin Sign In")
    adcWin.iconbitmap("images/icons/arcen.ico")
    adcWin.geometry("{}x{}+{}+{}".format(iWidth,iHeight,iwL,ihL))
    adcWin.maxsize(iWidth,iHeight)
    adcWin.resizable(False,False)
    ...
    ...
    ...
    entButton = tk.Button(TSFrame, text = "   Sign In   ", bd = 0, 
                  relief = "groove", bg = "#b9b9b9", command = adminVerification)
    entButton.grid(row = 0, column = 7)

Here is the releated button funcition which is adminVerification!

def adminVerification():
    global usmaEnt, uspsEnt, advCodeEnt, sendedCode, adcWin, advWin
    amail = usmaEnt.get()
    apass = uspsEnt.get()
    if amail != "" and apass != "":
        threading.Thread(target = intz.databaseConnection()).start()
        threading.Thread(target = intz.databaseOperations(6, amail, apass)).start() 
        conc = intz.conc
        if conc == 1:
            sendedCode = hps.codeGenerator(1)
            threading.Thread(target = hps.prepareMails(1,"Verification code is in below!", 
            sendedCode)).start()
            threading.Thread(target = hps.mailSender(hps.eps)).start()
            if hps.mService != 0:
                 adcWin.destroy()
                 iWidth = int(intz.width/2.6)
                 iHeight = int(intz.height/3.6)
                 iwL = int((intz.width-iWidth)/2)
                 ihL = int((intz.height-iHeight)/2)
                 advWin = tk.Tk()
                 advWin.title("ARCEN - Admin Verification")
                 advWin.iconbitmap("images/icons/arcen.ico")
                 advWin.geometry("{}x{}+{}+{}".format(iWidth,iHeight,iwL,ihL))
                 advWin.maxsize(iWidth,iHeight)
                 advWin.resizable(False,False)

After I clicked the button, I cannot do anything even I put thread operation.

So, what should I do?

Please help me!

Thanks.

0

There are 0 best solutions below