你好,我是悦创。
个人博客首发:https://www.aiyc.top/2129.html
1、抖音同款,不同意不许走
Coder1:https://gitee.com/huangjiabaoaiyc/image/raw/master/202112311324076.py
Coder2:https://github.aiyc.top/aiyccdn/py/202112311327181.py
# coding: utf8
from tkinter import *
from tkinter import messagebox
import random
def no_close():
return
#关闭所有窗口
def close_all_window():
window.destroy()
#关闭窗口提示
def close_window():
messagebox.showinfo(title="不要嘛~", message="不选好不许走!")
#“好的”窗口
def Love():
love = Toplevel(window)
love.geometry("300x100+580+250")
love.title("爱你么么哒~")
btn = Button(love, text="在一起!", width=10, height=2, command=close_all_window)
btn.place(x=100, y=30)
love.protocol("WM_DELETE_WINDOW", no_close)
window = Tk()
window.title("嗨,小姐姐") #窗口标题
window.geometry("360x640+550+50") #窗口大小
window.protocol("WM_DELETE_WINDOW", close_window) #窗口关闭
label = Label(window, text="观察你很久了", font=("微软雅黑", 18))
label.place(x=120, y=50)
label = Label(window, text="做我女朋友好不好?", font=("微软雅黑", 24))
label.place(x=70, y=100)
btn1 = Button(window, text="好", width=15, height=2, command=Love)
btn1.place(x=110, y=200)
# “不好”按钮
pos = [110, 300]
btn2 = Button(window, text="不好", width=15, height=2)
btn2.place(x=pos[0], y=pos[1])
def on_enter(e):
global pos
dx = random.randint(100, 200)
dy = random.randint(100, 300)
print(pos,dx,dy)
pos = (pos[0] + dx) % 200, (pos[1] - 250 + dy) % 350 + 250
btn2.place(x=pos[0], y=pos[1])
btn2.bind("<Enter>", on_enter)
#显示窗口,消息循坏
window.mainloop()
运行效果
2、动态彩色二维码表白
先在 pycharm 安装 myqr。或者,Python3 必装,然后命令行 pip install myqr
也可。
将表白网页:https://github.aiyc.top/love_demo/ 生成二维码,也可以换成其他连接
# myqr https://github.aiyc.top/love_demo/
line 16: mode: byte
Succeed!
Check out your 5-H QR-code: D:\Github_pages\HtmlGame\qrcode.png
生成二维码效果:
准备一张图片:lovelove.git
# myqr https://github.aiyc.top/love_demo/ -p lovelove.gif
It may take a while, please wait for minutes...
line 16: mode: byte
Succeed!
Check out your 5-H QR-code: D:\Github_pages\HtmlGame\lovelove_qrcode.gif
二维码效果:
彩色效果:
# myqr https://github.aiyc.top/love_demo/ -p lovelove.gif -c
It may take a while, please wait for minutes...
line 16: mode: byte
Succeed!
Check out your 5-H QR-code: D:\Github_pages\HtmlGame\lovelove_qrcode.gif
用微信扫码后显示效果:
3、表白树
# -*- coding: utf-8 -*-
# @Author: AI悦创
# @Date: 2021-12-16 14:55:28
# @Last Modified by: aiyc
# @Last Modified time: 2021-12-31 14:42:00
import turtle
import random
def love(x, y): # 在(x,y)处画爱心
lv = turtle.Turtle()
lv.hideturtle()
lv.up()
lv.goto(x, y) # 定位到(x,y)
def curvemove(): # 画圆弧
for i in range(20):
lv.right(10)
lv.forward(2)
lv.color('red', 'pink')
lv.speed(10000000)
lv.pensize(1)
# 开始画爱心lalala
lv.down()
lv.begin_fill()
lv.left(140)
lv.forward(22)
curvemove()
lv.left(120)
curvemove()
lv.forward(22)
lv.write("AI悦创", font=("Arial", 12, "normal"), align="center") # 写上要表白的人的名字
lv.left(140) # 画完复位
lv.end_fill()
def tree(branchLen, t):
if branchLen > 5: # 剩余树枝太少要结束递归
if branchLen < 20: # 如果树枝剩余长度较短则变绿
t.color("green")
t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
t.down()
t.forward(branchLen)
love(t.xcor(), t.ycor()) # 传输现在turtle的坐标
t.up()
t.backward(branchLen)
t.color("brown")
return
t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
t.down()
t.forward(branchLen)
# 以下递归
ang = random.uniform(15, 45)
t.right(ang)
tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度
t.left(2 * ang)
tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度
t.right(ang)
t.up()
t.backward(branchLen)
myWin = turtle.Screen()
t = turtle.Turtle()
t.hideturtle()
t.speed(1000)
t.left(90)
t.up()
t.backward(200)
t.down()
t.color("brown")
t.pensize(32)
t.forward(60)
tree(100, t)
myWin.exitonclick()
4、送你一朵玫瑰花
import turtle
import time
# writing txt
turtle.hideturtle()
turtle.penup()
turtle.goto(80, 50)
# turtle.pendown()
turtle.color("purple")
time.sleep(1)
#XX同学可以改为你自己的表白对象
turtle.write("女神,给你画个东西", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(180, 10)
turtle.write("马上开始咯", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(200, -20)
turtle.write("Ready?", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(215, -50)
turtle.write("go!", font=("Times", 18, "bold"))
time.sleep(0.5)
# turtle.end_fill()
#
# 设置初始位置
turtle.goto(0, 0)
turtle.color("black")
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10, 180)
turtle.circle(25, 110)
turtle.left(50)
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()
# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)
time.sleep(0.5)
turtle.penup()
turtle.color("orange")
turtle.goto(180, -100)
turtle.write("把我~送给你~", font=("Times", 18, "bold"))
turtle.goto(180, -120)
turtle.write("情人节快乐!", font=("Times", 18, "bold"))
time.sleep(10)
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。QQ、微信在线,随时响应!V:Jiabcdefh,公众号:AI悦创
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。