python无法拒绝的表白代码教程
很酷的python表白工具 你喜欢我吗本文实例为大家分享了python表白工具的具体代码,供大家参考,具体内容如下
实现代码:
|
# 打包操作 # 安装pyinstaller # cmd输入 pip install pyinstaller # shift+右击文件夹 点击在此处打开命令窗口 # pyinstaller -f -w love.py //打包程序 # 引用tkinter工具包 from tkinter import * #__all__=[a,b] #from tkinter import messagebox # 定义关闭窗口提示 def closewindow(): messagebox.showinfo(title = "警告" ,message = "滚回去,必须选一个" ) return # 定义喜欢按钮的提示 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 # 关闭所有窗口 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(): #messagebox.showinfo("放弃吧回去重选- -") #return nolove() # 创建窗口 window = tk() # 窗口标题 window.title( "喜欢我吗?" ) # 窗口大小 window.geometry( "380x420+500+240" ) # love.title("哈哈") btn = button(text = "确定" ) # 窗口位置 # window.geometry("+500+240") 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.jpg" alt="python无法拒绝的表白代码教程(很酷的python表白工具 你喜欢我吗)" border="0" /> 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() |
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。