0

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.

dralioz
  • 1
  • 2
  • Does this answer your question? [python threading blocks](https://stackoverflow.com/questions/15946075/python-threading-blocks) – Matiiss Dec 15 '21 at 19:02
  • It is working I know that but I have to give some parameters to the function. So, I try that with lambda: .... Still the problem continue but, I earn a second with that. Thank you. – dralioz Dec 15 '21 at 19:24
  • that is what `args` is for, you provide the arguments that need to be passed to the function as a tuple: `args=(arg1, arg2, ...)`, I would suggest that you read the documentation – Matiiss Dec 15 '21 at 19:37
  • Oh super! Thank you so much – dralioz Dec 15 '21 at 19:39
  • Also, Lambda is working very well. I found the another problem. – dralioz Dec 15 '21 at 19:44
  • yes, but don't use `lambda`, it takes up more memory space and `args` and `kwargs` are the intended way to pass the arguments – Matiiss Dec 15 '21 at 20:05
  • Ok, really thank you so much – dralioz Dec 15 '21 at 21:00
  • 1
    `threading.Thread(target = intz.databaseConnection())` will _instantly_ run `intz.databaseConnection()` before passing the result to the thread. – Bryan Oakley Dec 15 '21 at 21:04

0 Answers0