我需要得到一个单独的窗口的一部分,以输出文本的基础上发生了什么,例如,4电子邮件发送将如下所示:发送...成功:已发送电子邮件!成功:已发送电子邮件!成功:已发送电子邮件!成功:已发送电子邮件!所有4封电子邮件都已成功发送!
import smtplib
from tkinter import *
root = Tk()
root.title("Inbox Flooder")
root.geometry("720x520+0+0")
root.configure(background="black")
def click():
global YOUR_EMAIL_ADDRESS , YOUR_PASSWORD , AMNT_REPEAT , TARGET_EMAIL , subject , msg
YOUR_EMAIL_ADDRESS=YOUR_EMAIL_ADDRESS.get()
YOUR_PASSWORD=YOUR_PASSWORD.get()
TARGET_EMAIL=TARGET_EMAIL.get()
subject=subject.get()
msg=msg.get()
AMNT_REPEAT=AMNT_REPEAT.get()
print("Starting...")
while int(AMNT_REPEAT) > 0 :
send_email(subject, msg)
AMNT_REPEAT = int(AMNT_REPEAT) - 1
if failed > 0 and sent > 0 :
print(sent,"email(s) have been sucessfully sent and",failed ,"emails have failed to send.")
if failed > 0 and sent == 0 :
print("All",failed ,"emails have failed to send.")
if failed == 0 and sent > 0 :
print("All",sent ,"emails have sucessfully been sent!")
def send_email(subject, msg):
global sent , failed
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(YOUR_EMAIL_ADDRESS, YOUR_PASSWORD)
message = 'Subject: {}\n\n{}'.format(subject, msg)
server.sendmail(TARGET_EMAIL, TARGET_EMAIL, message)
server.quit()
print("Sucess: Email sent!")
sent = sent + 1
except:
print("Error: Email failed to send.")
failed = failed + 1
def close_window():
try:
root.destroy()
exit()
except:
print("Tab Closed")发布于 2020-06-09 03:34:08
下面是一个简单的程序,它在窗口打开时循环,添加“成功:发送电子邮件!”这只不过是演示如何向基本的tkinter GUI添加内容。
然而,你将需要使用线程,因为你的发送应该在窗口打开时在后台执行,这将需要一些适当的研究,我不会在这里解释这个过程(另一个线程应该很容易找到)。
import tkinter as tk
def send_success():
# Allow us to insert into the widget
logt.config(state="normal")
# Insert into the widget (adding a newline at the end)
logt.insert("end", "Success: Email sent!\n")
# Disable user changes again
logt.config(state="disabled")
# Scroll to bottom of widget (to show new text)
logt.see("end")
# Schedule a call to ourselves after 1 second
root.after(1000, send_success)
# Create the main tkinter window
root = tk.Tk()
# Create our text widget (normally a multi-line text
# entry widget, but this will be our log widget)
logt = tk.Text(root)
# Add the widget to the window
# (and set it to increase in size with the window)
logt.pack(side="left", fill="both", expand=True)
# Stop people changing the content
logt.config(state="disabled")
# Create a vertical scrollbar
sc = tk.Scrollbar(root)
# Add the widget to the window
sc.pack(side="right", fill="y")
# Move the text widget when scrollbar moved
sc.config(command=logt.yview)
# Change scrollbar length when new content added
logt.config(yscrollcommand=sc.set)
# Schedule our method to run once the mainloop is running
root.after(0, send_success)
# Run the mainloop
# This handles window actions (moving, resizing, etc.)
root.mainloop()https://stackoverflow.com/questions/62264964
复制相似问题