这篇文章带大家实现表白代码
看过很多用批处理写的表白就想着用Python实现一个
实现用的是tkinter
点击关闭按钮 无法关闭
def closeWindow():
messagebox.showinfo(title"警告", message"关不掉吧气不气")
return
点击不喜欢的事件
def noLove():
no_love Toplevel(window)
no_love.geometry("300x100610260")
no_love.title("我好喜欢你")
label Label(no_love, text"再考虑考虑呗", font("华文行楷", 25))
label.pack()
btn Button(
no_love,
text"好吧",
width10,
height2,
commandno_love.destroy)
btn.pack()
no_love.protocol("WM_DELETE_WINDOW", closeNoLove)
def closeNoLove():
# messagebox.showinfo("不喜欢我你就关不掉")
messagebox.showinfo(title"警告", message"不喜欢我你就关不掉")
noLove()
点击喜欢 然后关闭窗体的事件
def closelove():
messagebox.showinfo(title"好怂啊你", message"喜欢我直说就行")
return
喜欢的事件
def love():
love Toplevel(window)
love.geometry("300x150610260")
love.title("好巧啊我也喜欢你")
label Label(love, text"如家酒店A350等你", font("华文行楷", 20))
label.pack()
label Label(love, text"电话给我美滋滋", font("华文行楷", 25))
label.pack()
entry Entry(love, font("楷体", 15))
entry.pack()
btn Button(love, text"嗯嗯", width10, height2, commandcloseallwindow)
btn.pack()
love.protocol("WM_DELETE_WINDOW", closelove)
完整代码如下
from tkinter import *
from tkinter import messagebox
def closeallwindow():
window.destroy()
def closeWindow():
messagebox.showinfo(title"警告", message"关不掉吧气不气")
return
def love():
love Toplevel(window)
love.geometry("300x150610260")
love.title("好巧啊我也喜欢你")
label Label(love, text"如家酒店A350等你", font("华文行楷", 20))
label.pack()
label Label(love, text"电话给我美滋滋", font("华文行楷", 25))
label.pack()
entry Entry(love, font("楷体", 15))
entry.pack()
btn Button(love, text"嗯嗯", width10, height2, commandcloseallwindow)
btn.pack()
love.protocol("WM_DELETE_WINDOW", closelove)
def closelove():
messagebox.showinfo(title"好怂啊你", message"喜欢我直说就行")
return
def noLove():
no_love Toplevel(window)
no_love.geometry("300x100610260")
no_love.title("我好喜欢你")
label Label(no_love, text"再考虑考虑呗", font("华文行楷", 25))
label.pack()
btn Button(
no_love,
text"好吧",
width10,
height2,
commandno_love.destroy)
btn.pack()
no_love.protocol("WM_DELETE_WINDOW", closeNoLove)
def closeNoLove():
# messagebox.showinfo("不喜欢我你就关不掉")
messagebox.showinfo(title"警告", message"不喜欢我你就关不掉")
noLove()
window Tk()
window.title("喜欢我么,来自一个漂亮女生的告白")
window.geometry("420x300590230")
window.protocol("WM_DELETE_WINDOW", closeWindow)
label1 Label(window, text"小姐姐关注你很久了",
font("华文行楷", 16), fg"red")
label1.grid()
label2 Label(window, text"喜欢我么", font("华文行楷", 30))
label2.grid(row1, column1, stickyE)
photo PhotoImage(file"cc.gif")
imageLable Label(window, imagephoto)
imageLable.grid(row2, columnspan2)
btn1 Button(window, text"愿意", width15, height2, commandlove)
btn1.grid(row3, column0, stickyW)
btn2 Button(window, text"不愿意", width15, height2, commandnoLove)
btn2.grid(row3, column1, stickyE)
window.mainloop()
效果图如下
在这里插入图片描述
一起学习python小白指导教学分享记得私信我