花了一周终于整理好了!全网最全Python tkinter教程!包含所有知识点!


from tkinter import tkbooks
from random import random#随机移动
import tkinter as tk
root= tk.Tk()
root.geometry('500*300+100+100')
root.title('辞职信')
frame1=tk.Frame(root)
frame1.pack()
#当成画布
tk.Label(frame1,text='尊敬的各位领导:',#调字体font=24,padx=30,pady=30).pack(side=tk.LEFT,(对齐方式anchor=tk.N)
img=tk.PhotoImage(file='resignation/farewall.png')#加载图片
label_img=tk.Label(frame1,image=img,padx=30,pady=30,bd=0)
label_img.pack(side=tk.LEFT,anchor=th.N)
tk.Label(frame1,text='辞职人:',#调字体height=30,font=24,padx=30,pady=30,anchor=tk.S).pack(side=tk.LEFT,(对齐方式)
yes_img=tk.PhotoImage(file='resignation/yes.png')
no_img=tk.PhotoImage(file='resignation/no.png')
yes_btn=tk.Button(frame1,image=yes_img,bd=0)
no_btn=tk.Button(frame1,image=no_img,bd=0)
#计算一下相对位置
yes_btn.place(relx=0.3,rely=0.8,anchor=tk.CENTER)
no_btn.place(relx=0.7,rely=0.8,anchor=tk.CENTER)
#页面二
frame2=tk.Frame(root)
frame2.pack()
tk.Label(frame2,text='再见',
font=('黑体',18),justify=tk.LEFT,#对齐方式
height=300,fg='red'#字体颜色
padx=50).pack()
tk.Button(frame2,text='退出',
command=root.quit).place(relx=0.8,rely=0.9)
root.mainloop()
#不允许关闭
def on_exit():
messagebox.showwarning(title='提示',message='此路不通')
root.protocol('WM_DELEIE')
def move(event):
no_btn.place(relx=random(),rely=random(),anchor=tk.CENTER)
no_btn.bind('<Enter>',move)
def sure():
frame1.pack_forget()
frame2.pack()
yes_btn.connfig(command=sure)
root.mainloop() (显示窗体)

