import tkinter as tk
from tkinter import messagebox
from random import random
window = tk.Tk()
window.title('请我吃饭!!')
window.geometry('350x300+100+100')
window.resizable(False,False)
window.iconbitmap(bitmap=r"C:\Users\Downloads\1.ico")
frame1 = tk.Frame(window)
frame1.pack()
tk.Label(frame1,text='朋友,请我吃个大餐吧!',font=('楷体',12),bg='yellow',padx=10,pady=30,anchor=tk.N,height=4).pack(side=tk.LEFT,anchor=tk.N)
img = tk.PhotoImage(file=r"C:\Users\Downloads\111.gif")
label_img = tk.Label(frame1,image=img,width=140,height=130,bd=0)
label_img.pack(side=tk.LEFT,anchor=tk.N)
tk.Label(frame1,text='5\n2\n0',height=25,font=('楷体',12),bg='blue',anchor=tk.S).pack(side=tk.LEFT)
yes_img = tk.PhotoImage(file=r'C:\Users\Downloads\yes_btn.png')
no_img = tk.PhotoImage(file=r'C:\Users\Downloads\no_btn.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.82,anchor=tk.CENTER)
no_btn.place(relx=0.7,rely=0.82,anchor=tk.CENTER)
frame2 = tk.Frame(window)
# frame2.pack()
tk.Label(frame2,text='(#^.^#)\n\n走起,撸串去!!!',
font=('黑体',18),
height=16,
justify=tk.LEFT, # 字符左对齐
fg='red',
bg='white',
padx=50
).pack()
tk.Button(frame2,text='走起',relief='ridge',command=window.quit).place(relx=0.86,rely=0.8)
def on_exit():
tk.messagebox.showinfo(title='拜托',message='再考虑考虑!!')
window.protocol('WM_DELETE_WINDOW',on_exit)
def move(event):
no_btn.place(relx=random(),rely=random(),anchor=tk.CENTER)
no_btn.bind('<Enter>',move)
def agree():
frame1.pack_forget()
frame2.pack()
yes_btn.config(command=agree)
window.mainloop()
运行效果:
无法点击×关闭
无法点击不行按键,当鼠标放到按键时,按键位置改变
只能选择好呀,点击走起按键,退出
标签:img,Python,window,搞怪,UI,tk,frame1,btn,pack From: https://blog.51cto.com/u_15109749/8361295