QWEcf123 发表于 2022-7-8 04:19

【原创源码】表白小程序



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

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

cqy666 发表于 2022-7-8 10:42

人生苦短,就用python

mjai5 发表于 2022-7-8 10:50

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

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

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()
    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()

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

学到了,表白对象哪里领。{:1_937:}

acchao 发表于 2022-7-8 13:37

挺高的,之前在网上见过,不过找不到,感谢楼主
页: [1] 2 3
查看完整版本: 【原创源码】表白小程序