一、制作背景
放假期间查看自己上份工作的辞职报告,回想离职时老板的各种刁难,突发奇想使用软件写一个让老板无法拒绝的辞职小程序^_^^_^
二、小程序使用体验
1,)小程序主界面
2,)如果领导点击不同意【按键会跑,不会让你抓住^_^】
3,)如果领导点击左上角的关闭按钮【提示此路不通^_^】
4,所以最后,只能是点击同意~~
5,最后,同意之后,再点击退出,程序即可退出成功~
三、小程序代码逻辑
1,导入tkinter模块,使用tkinter构建弹窗
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.geometry('725x400+100+100')
root.title('辞职信')
root.mainloop()
2,配置2个页面,分别为弹窗主界面和点击同意后的第二张界面
frame1 = tk.Frame(root)
frame1.pack()
frame2 = tk.Frame(root)
# frame2.pack()
3,配置第一个界面信息
tk.Label(frame1, text='\n老板,我考上税务局公务员了,\n\n你准备跑路吧!!!', font=24, padx=20, pady=30).pack(side=tk.LEFT, anchor=tk.N)
img = tk.PhotoImage(file='3.gif')
label_img = tk.Label(frame1, image=img, padx=20, pady=30, bd=0)
label_img.pack(side=tk.LEFT, anchor=tk.N)
tk.Label(frame1, text='辞职人:正心', height=25, font=24, padx=20, pady=350, anchor=tk.N).pack(side=tk.LEFT)
yes_command = tk.Button(frame1, font=24, text='同意', bd=0)
no_command = tk.Button(frame1, font=24, text='不同意', bd=0)
yes_command.place(relx=0.3, rely=0.8, anchor=tk.CENTER)
no_command.place(relx=0.7, rely=0.8, anchor=tk.CENTER)
4,配置第二个界面的信息
tk.Label(frame2, text='老板大人,臣告退了\n这一退,可能就是一辈子了\n!!!!^_^!!!!', font=('黑体', 18), justify=tk.LEFT, height=300, fg='red',
padx=50).pack()
tk.Button(frame2, text='退出', font=('黑体', 18), command=root.quit).place(relx=0.8, rely=0.8)
5,引入random库,配置"不同意"按钮飘逸,(不让老板点击^_^ 不同意 ^_^按钮)
from random import random
def move(event):
no_command.place(relx=random(), rely=random(), anchor=tk.CENTER)
no_command.bind('<Enter>', move)
6,配置 此路不通 按钮,即不能通过关闭窗口来关闭小程序
def on_exit():
messagebox.showwarning(title='提示', message='此路不通')
root.protocol('WM_DELETE_WINDOW', on_exit)
7,配置 点击同意,则跳转至第二界面
def sure():
frame1.pack_forget()
frame2.pack()
yes_command.config(command=sure)
到此~ 程序完成~
备注:代码已生成桌面小程序,有需要可留言哦~~