吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3309|回复: 23
收起左侧

[Python 原创] 【原创源码】表白小程序

[复制链接]
QWEcf123 发表于 2022-7-8 04:19


小白闲的无聊 写了一个表白的小程序

[Python] 纯文本查看 复制代码
from tkinter import *
from tkinter import messagebox


def close_window():
    messagebox.showinfo(title="警告", message="不许关闭,好好回答")
    return


def love():
    love2 = Toplevel(window)
    love2.geometry("300x100+520+260")
    love2.title("好巧,我也是")
    label2 = Label(love2, text="好巧,我也是", font=("微软雅黑", 20))
    label2.pack()
    btn2 = Button(love2, text="确定", width=10, height=2, command=close_all_window)
    btn2.pack()
    love2.protocol("WM_DELETE_WINDOW", close_love)


def close_love():
    return


def close_all_window():
    window.destroy()


def no_love():
    no_love2 = Toplevel(window)
    no_love2.geometry("300x100+520+260")
    no_love2.title("再考虑考虑")
    label2 = Label(no_love2, text="再考虑考虑呗", font=("微软雅黑", 25))
    label2.pack()
    btn2 = Button(no_love2, text="好的", width=10, height=2, command=no_love2.destroy)
    btn2.pack()
    no_love2.protocol("WM_DELETE_WINDOW", close_no_love)


def close_no_love():
    no_love()


window = Tk()
window.title("你喜欢我吗?")
window.geometry('380x450')
window.geometry('+500+240')
window.protocol("WM_DELETE_WINDOW", close_window)
label = Label(window, text="hey,女神名字", font=("微软雅黑", 15), fg='red')
label.grid(row=0, column=0, sticky=W)
label1 = Label(window, text="喜欢我吗?", font=("微软雅黑", 30))
label1.grid(row=1, column=1, sticky=E)
photo = PhotoImage(file="女神照片.png")
image_label = Label(window, image=photo)
image_label.grid(row=2, columnspan=2)
btn = Button(window, text="喜欢", width=15, height=2, command=love)
btn.grid(row=3, column=0, sticky=W)
btn1 = Button(window, text="不喜欢", command=no_love)
btn1.grid(row=3, column=1, sticky=E)
window.mainloop()


单文件:https://wwm.lanzouv.com/ipmkn07j3tgf

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
shanhu5235 + 1 + 1 缩小框再绑定个事件就更好玩了

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

cqy666 发表于 2022-7-8 10:42
人生苦短,就用python
mjai5 发表于 2022-7-8 10:50

修改了一下,可以打开其他类型的图片了,图片打开后缩放了,以便全部显示出来

本帖最后由 mjai5 于 2022-7-8 10:52 编辑

[Python] 纯文本查看 复制代码
from tkinter import *
from tkinter import messagebox
from PIL import Image
from PIL import ImageTk

#修改了一下,可以打开其他类型的图片了,图片打开后缩放了,以便全部显示出来
 
def close_window():
    messagebox.showinfo(title="警告", message="不许关闭,好好回答")
    return
 
 
def love():
    love2 = Toplevel(window)
    love2.geometry("300x100+520+260")
    love2.title("好巧,我也是")
    label2 = Label(love2, text="好巧,我也是", font=("微软雅黑", 20))
    label2.pack()
    btn2 = Button(love2, text="确定", width=10, height=2, command=close_all_window)
    btn2.pack()
    love2.protocol("WM_DELETE_WINDOW", close_love)
 
 
def close_love():
    return
 
 
def close_all_window():
    window.destroy()
 
 
def no_love():
    no_love2 = Toplevel(window)
    no_love2.geometry("300x100+520+260")
    no_love2.title("再考虑考虑")
    label2 = Label(no_love2, text="再考虑考虑呗", font=("微软雅黑", 25))
    label2.pack()
    btn2 = Button(no_love2, text="好的", width=10, height=2, command=no_love2.destroy)
    btn2.pack()
    no_love2.protocol("WM_DELETE_WINDOW", close_no_love)
 
 
def close_no_love():
    no_love()

def f1(w_, h_, png_image):
    '''
    w_ : 要适应的窗口宽
    h_ : 要适应的窗口高
    png_image : Image.open后的图片
    '''
    w, h = png_image.size  # 获取图像的原始大小
    f1 = 1.0 * w_ / w
    f2 = 1.0 * h_ / h
    factor = min([f1, f2])
    width = int(w * factor)
    height = int(h * factor)
    return png_image.resize((width, height), Image.ANTIALIAS)
 
 
window = Tk()
window.title("你喜欢我吗?")
window.geometry('380x450')
window.geometry('+500+240')
window.protocol("WM_DELETE_WINDOW", close_window)
label = Label(window, text="hey,美羊羊", font=("微软雅黑", 15), fg='red')
label.grid(row=0, column=0, sticky=W)
label1 = Label(window, text="喜欢我吗?", font=("微软雅黑", 30))
label1.grid(row=1, column=1, sticky=E)

image = Image.open("d:0.jpg")
png_image_resized = f1(380, 280, image)
photo = ImageTk.PhotoImage(png_image_resized)
#photo = PhotoImage(file="d:0.jpg")

image_label = Label(window, image=photo)
image_label.grid(row=2, columnspan=2)
btn = Button(window, text="喜欢", width=15, height=2, command=love)
btn.grid(row=3, column=0, sticky=W)
btn1 = Button(window, text="不喜欢", command=no_love)
btn1.grid(row=3, column=1, sticky=E)
window.mainloop()
0.gif
nihao3312 发表于 2022-7-8 10:20
d199212 发表于 2022-7-8 10:21
看起来好不错哦
metoo2 发表于 2022-7-8 10:36
围观支持~~
福森108 发表于 2022-7-8 11:32
厉害,谢谢分享
Bloomderest 发表于 2022-7-8 13:01
可以的,多谢分享。
Herculee 发表于 2022-7-8 13:25
学到了,表白对象哪里领。
acchao 发表于 2022-7-8 13:37
挺高的,之前在网上见过,不过找不到,感谢楼主
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 03:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表