相较于上一版本进行了细节上的优化,增强了程序的友好性,支持程序外部自定义投票范围
这是程序主体:
import easygui
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
from easygui import*
import webbrowser
import smtplib
import os
host_server = ' '#发件邮箱smtp地址 例 smtp.qq.com
sender_qq = ' '#发件邮箱的地址 例 [email protected]
pwd = ' ' #邮箱授权码
sender_qq_mail = ' ' #发件邮箱的地址 例 [email protected]
receiver = ' ' #收件邮箱的地址
print("请不要随意输入,程序已内置判断条件")
lanrenmoshi = easygui.buttonbox("班级投票————此版本再次优化了判断逻辑,并精简了代码 python版制作人:宋勃逸 网页版制作人:徐睿博",choices =('开始投票','网页版投票/更新版本',"bug反馈"))
if lanrenmoshi=="网页版投票/更新版本":
webbrowser.open_new_tab('https://bit1.mysxl.cn/')
if lanrenmoshi=="bug反馈":
mail_content = easygui.enterbox(msg="请描述您所发现的bug:",title = "bug反馈")
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(mail_content, "plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
fankuiwancheng=easygui.buttonbox("bug反馈————感谢您对程序的支持",choices =("完事啦~~"))
if lanrenmoshi=="开始投票":
try:
classes_path = os.path.expanduser('自定义名字.txt')
with open(classes_path,'r',encoding = 'UTF-8') as f:
data = f.readlines()
data = [c.strip() for c in data]
except:
classes_path = os.path.expanduser('自定义名字.txt')
with open(classes_path,'r',encoding = 'gbk') as f:
data = f.readlines()
data = [c.strip() for c in data]
mail_content = multchoicebox(msg='请选择6个你要投的人,程序以内置判断,欸嘿', title='投票', choices=(data))
if len(mail_content)>6 or len(mail_content)<6:
mail_content = multchoicebox(msg='只能投6个人哦如果再不按照要求投,程序会直接跳出!!!', title='投票', choices=(data))
if len(mail_content)>6 or len(mail_content)<6:
qisiwola=easygui.buttonbox("不得不说,如果你能看到这行提示说明程序已经快被你玩坏了,emmmmm...... 你这个样子让作者也很难做啊",choices =('下一步',))
eihie=easygui.buttonbox("下次记得好好输入昂————",choices =("离开"))
else:
sender_qq = '[email protected]'
pwd = 'xwavztavrctkbfej'
sender_qq_mail = '[email protected]'
receiver = easygui.enterbox(msg="请输入统计投票人的邮箱,当然您也可以先输入自己的邮箱进行设置",title = "投票")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("请检查您输入的邮箱是否正确",choices =('重新输入',))
sender_qq = ' '#同上
pwd = ' ' #同上
sender_qq_mail = ' ' #同上
receiver = easygui.enterbox(msg="请重新输入统计投票人的邮箱",title = "投票")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("请再次检查您输入的邮箱是否正确~~",choices =('重新输入',))
sender_qq = ' ' #同上
pwd = ' ' #同上
sender_qq_mail = ' ' #同上
receiver = easygui.enterbox(msg="请”再次“重新输入统计投票人的邮箱",title = "重试")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("很可惜,您已经没有机会了————再见",choices =("结束",))
os._exit ()
else:
sender_qq = ' ' #同上
pwd = ' ' #同上
sender_qq_mail = ' ' #同上
receiver = easygui.enterbox(msg="请输入统计投票人的邮箱,当然您也可以先输入自己的邮箱进行设置",title = "投票")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("请检查您输入的邮箱是否正确",choices =('重新输入',))
sender_qq = ' ' #同上
pwd = ' ' #同上
sender_qq_mail = ' ' #同上
receiver = easygui.enterbox(msg="请重新输入统计投票人的邮箱",title = "投票")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("请再次检查您输入的邮箱是否正确~~",choices =('重新输入',))
sender_qq = ' ' #同上
pwd = ' ' #同上
sender_qq_mail = ' ' #同上
receiver = easygui.enterbox(msg="请”再次“重新输入统计投票人的邮箱",title = "重试")
shuju=(" ".join(mail_content))
mail_title = '投票'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEText(shuju,'text','utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
try:
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
wanjisahua=lanrenmoshi = easygui.buttonbox("完结,撒花!",choices =('~离开~'))
except:
a=easygui.buttonbox("很可惜,您已经没有机会了————再见",choices =("结束",))
os._exit ()
还需要一个名字为:自定义名字.txt 的文本文件,这个文本文件需和程序主体放在同一个文件夹
就是这样一个目录结构
自定义投票人选的格式:
一定要是一行一个人名
怎么样,很简单吧
如有更好的解决办法可在评论区发表,或者邮箱发给作者