这篇文章带大家实现表白代码
看过很多用批处理写的表白,就想着用Python实现一个
实现用的是tkinter
点击关闭按钮 无法关闭
def closeWindow():
messagebox.showinfo(title=”警告”, message=”关不掉吧,气不气”)
return
点击不喜欢的事件
def noLove():
no_love = Toplevel(window)
no_love.geometry(“300×100+610+260”)
no_love.title(“我好喜欢你”)
label = Label(no_love, text=”再考虑考虑呗”, font=(“华文行楷”, 25))
label.pack()
btn = Button(
no_love,
text=”好吧”,
width=10,
height=2,
command=no_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(“300×150+610+260”)
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=”嗯嗯”, width=10, height=2, command=closeallwindow)
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(“300×150+610+260”)
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=”嗯嗯”, width=10, height=2, command=closeallwindow)
btn.pack()
love.protocol(“WM_DELETE_WINDOW”, closelove)
def closelove():
messagebox.showinfo(title=”好怂啊你”, message=”喜欢我直说就行”)
return
def noLove():
no_love = Toplevel(window)
no_love.geometry(“300×100+610+260”)
no_love.title(“我好喜欢你”)
label = Label(no_love, text=”再考虑考虑呗”, font=(“华文行楷”, 25))
label.pack()
btn = Button(
no_love,
text=”好吧”,
width=10,
height=2,
command=no_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(“420×300+590+230”)
window.protocol(“WM_DELETE_WINDOW”, closeWindow)
label1 = Label(window, text=”小姐姐关注你很久了!”,
font=(“华文行楷”, 16), fg=”red”)
label1.grid()
label2 = Label(window, text=”喜欢我么?”, font=(“华文行楷”, 30))
label2.grid(row=1, column=1, sticky=E)
photo = PhotoImage(file=”cc.gif”)
imageLable = Label(window, image=photo)
imageLable.grid(row=2, columnspan=2)
btn1 = Button(window, text=”愿意”, width=15, height=2, command=love)
btn1.grid(row=3, column=0, sticky=W)
btn2 = Button(window, text=”不愿意”, width=15, height=2, command=noLove)
btn2.grid(row=3, column=1, sticky=E)
window.mainloop()
效果图如下:
在这里插入图片描述
一起学习python,小白指导,教学分享记得私信我
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/182201.html原文链接:https://javaforall.cn