相信大家都看过在网络上有那种表白神器,就是那种不同意就不能关闭窗口,这样的技术在小白眼中特别高级,但身为技术人员的我们,这样的东西还不是小菜一碟,没有人表白咱们咱还不能自我表白嘛
前置准备
我们这里使用的编程语言是Python,使用的库是tkinter,还有其他的一些模块如requests等
其中的第三方库有requests、PIL
安装方法
pip install 库名称
此外,我们打包exe文件需要用到pyinstaller,安装方法也是pip
窗口设计
我们先来做一个好看的窗口,只有这样才能获得女神的芳心

关键代码如下
from tkinter import *
from tkinter import messagebox
from requests import get
from PIL import Image,ImageTk
import sys
class Window(object):
def __init__(self):
self.window=Tk()
self.title="一个爱慕你的小哥哥"
self.size=(500,340)
self.image=Image.open('./love.jpg')
def show(self):
self.window.geometry("%dx%d"%self.size)
self.window.title(self.title)
label1=Label(self.window,text="小姐姐,我喜欢你很久了",font=("微软雅黑",15)).place(x=0,y=0)
tk_image=ImageTk.PhotoImage(self.image)
img_label=Label(self.window,image=tk_image).place(x=0,y=40)
label2=Label(self.window,text="你同意我吗?",font=('微软雅黑',30),fg='red').place(x=220,y=150)
agree_b=Button(self.window,text="同意",bg="#4e6ef2",fg="#fff",font=('微软雅黑'

使用Python和tkinter库创建了一个无法拒绝的表白窗口,展示了如何设计窗口、监听事件并阻止关闭。

6179

被折叠的 条评论
为什么被折叠?



