前言
马上情人节了,送什么给你女神呢。鲜花?口红?香水?还远远不够!再写一个告白程序,给她一个惊喜!那才刚刚好,保证是最特别的礼物!
我们做所有事情都要有一个思路, 写一个程序也不例外,本文代码分为了4个步骤
- 引用tkinter工具包
- 关闭所有窗口
- 定义不喜欢按钮的提示
- 窗口不能关
引用tkinter工具包
from tkinter import * #__all__=[a,b]
from tkinter import messagebox
定义喜欢按钮的提示
def Love():
love = Toplevel(window)
love.geometry("300x100+250+260")
love.title("我也喜欢你")
label = Label(love, text = "我也喜欢你!",font = ("微软雅黑",20))
label.pack()
btn = Button(love,text = "好呀",width = 10,height = 2,command=closeallwindow)
btn.pack()
love.protocol("WM_DELETE_WINDOW", closelove)
def closelove():
return
如果你跟我一样都喜欢python,想成为一名优秀的程序员,也在学习python的道路上奔跑,欢迎你加入python学习群:python群号:491308659 验证码:南烛 或者加扣扣1346525417
群内每天都会分享最新业内资料,分享python免费课程,共同交流学习,让学习变(编)成(程)一种习惯!
关闭所有窗口
def closeallwindow():
window.destroy()
定义不喜欢按钮的提示
def noLove():
no_love = Toplevel(window)
no_love.geometry("300x100+520+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():
noLove()
window = Tk()
window.title("喜欢我吗?")
window.geometry("380x420+500+240")
btn=Button(text="确定")
window.protocol("WM_DELETE_WINDOW",closeWindow )
label = Label(window,text = "hey,小姐姐",font = ("微软雅黑",15),fg = "red")
label.grid(row = 0, column = 0 )
label = Label(window,text = "喜欢我吗?",font = ("微软雅黑",30))
label.grid(row = 1, column = 1,sticky = E)
photo = PhotoImage(file = "./123.png")
imageLable = Label(window,image = photo)
imageLable.grid(row = 2,columnspan = 2)
btn = Button(window,text="喜欢",width=15,height=2,command=Love)
btn.grid(row=3,column=0,sticky= W)
btn = Button(window,text="不喜欢" ,command=noLove)
btn.grid(row=3,column=1,sticky= E)
window.mainloop()
网友评论