系列文章

序号文章目录直达链接
1浪漫520表白代码https://want595.blog.csdn.net/article/details/130666881
2满屏表白代码https://want595.blog.csdn.net/article/details/129794518
3跳动的爱心https://want595.blog.csdn.net/article/details/129503123
4漂浮爱心https://want595.blog.csdn.net/article/details/128808630
5爱心光波https://want595.blog.csdn.net/article/details/132311588
6流星雨https://want595.blog.csdn.net/article/details/129395465
7满天星https://want595.blog.csdn.net/article/details/129572082
8烟花秀https://want595.blog.csdn.net/article/details/128746664
9圣诞树https://want595.blog.csdn.net/article/details/128213770
10雪花代码https://want595.blog.csdn.net/article/details/129038108
11模拟星空https://want595.blog.csdn.net/article/details/129948882
12生日蛋糕https://want595.blog.csdn.net/article/details/129694998
13樱花树https://want595.blog.csdn.net/article/details/130350743
14五彩气球https://want595.blog.csdn.net/article/details/130950744
15七彩花朵https://want595.blog.csdn.net/article/details/130897838
16恶搞代码https://want595.blog.csdn.net/article/details/131274862

目录

系列文章

前言

爱心界面

无限弹窗


前言

人生苦短,我用Python!又是新的一周啦,本期博主给大家带来了一个全新的作品:满屏表白代码,无限弹窗版!快快收藏起来送给她吧~

爱心界面

程序设计

def Heart():root=tk.Tk()screenwidth=root.winfo_screenwidth()screenheight=root.winfo_screenheight()width=600height=400x=(screenwidth-width)//2y=(screenheight-height)//2root.title("❤")root.geometry("%dx%d+%d+%d"%(screenwidth,screenheight,0,0))tk.Label(root,text='❤',fg='pink',bg='white',font=("Comic Sans MS",500),width=300,height=20).pack()root.mainloop() 

程序分析

这是一个使用Python的Tkinter库创建窗口的程序,该程序会在屏幕中央显示一个红色的心形图案。程序首先导入了Tkinter库,并定义了一个名为Heart的函数。在函数中,程序定义了一个Tk窗口对象,并获取了当前屏幕的宽度和高度。接着程序定义了窗口的宽度和高度,并计算了窗口在屏幕中的位置。程序设置了窗口的标题为”❤”,并且使用geometry方法将窗口的大小和位置设置为占据整个屏幕。程序使用一个Label标签对象将一个大号的红色心形文本添加到窗口中,并使其在屏幕中央居中。最后,程序进入Tkinter的事件循环中,以响应用户的输入和操作。

无限弹窗

def Love1():
root=tk.Tk()
width=200
height=50
screenwidth=root.winfo_screenwidth()
screenheight=root.winfo_screenheight()
x=ra.randint(0,screenwidth/2)
y=ra.randint(0,screenheight/2)
root.title(“❤”)
root.geometry(“%dx%d+%d+%d”%(width,height,x,y))
tk.Label(root,text=’I LOVE YOU!’,fg=’white’,bg=’pink’,font=(“Comic Sans MS”,15),width=30,height=5).pack()
root.mainloop()
def Love2():
root=tk.Tk()
width=200
height=50
screenwidth=root.winfo_screenwidth()
screenheight=root.winfo_screenheight()
screenheight-=2*width
x=ra.randint(screenwidth/2,screenwidth)
y=ra.randint(0,screenheight/2)
root.title(“❤”)
root.geometry(“%dx%d+%d+%d”%(width,height,x,y))
tk.Label(root,text=’I LOVE YOU!’,fg=’white’,bg=’pink’,font=(“Comic Sans MS”,15),width=30,height=5).pack()
root.mainloop()
def Love3():
root=tk.Tk()
width=200
height=50
screenwidth=root.winfo_screenwidth()
screenheight=root.winfo_screenheight()
screenheight-=width
x=ra.randint(screenwidth/2,screenwidth)
y=ra.randint(screenheight/2,screenheight)
root.title(“❤”)
root.geometry(“%dx%d+%d+%d”%(width,height,x,y))
tk.Label(root,text=’I LOVE YOU!’,fg=’white’,bg=’pink’,font=(“Comic Sans MS”,15),width=30,height=5).pack()
root.mainloop()
def Love4():
root=tk.Tk()
width=200
height=50
screenwidth=root.winfo_screenwidth()
screenheight=root.winfo_screenheight()
screenheight-=2*width
x=ra.randint(0,screenwidth/2)
y=ra.randint(screenheight/2,screenheight)
root.title(“❤”)
root.geometry(“%dx%d+%d+%d”%(width,height,x,y))
tk.Label(root,text=’I LOVE YOU!’,fg=’white’,bg=’pink’,font=(“Comic Sans MS”,15),width=30,height=5).pack()
root.mainloop()

(完整程序文末公众免费领取哦)