Python满屏表白代码

发布于:2023-09-14 ⋅ 阅读:(116) ⋅ 点赞:(0)

系列文章 

序号 文章目录 直达链接
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=600
    height=400
    x=(screenwidth-width)//2
    y=(screenheight-height)//2
    root.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()

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


网站公告

今日签到

点亮在社区的每一天
去签到