Python搞怪UI设计

该程序使用tkinter库构建了一个GUI窗口,包含一个请求朋友请客吃饭的界面,有动态移动的不行按钮和好呀按钮。当用户点击好呀,显示新的确认信息并关闭窗口;点击不行,按钮会随机移动。程序还定义了一个on_exit函数,当尝试关闭窗口时会弹出提示信息。
摘要由CSDN通过智能技术生成
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()

运行效果:
在这里插入图片描述

无法点击×关闭
在这里插入图片描述

无法点击不行按键,当鼠标放到按键时,按键位置改变
在这里插入图片描述

只能选择好呀,点击走起按键,退出
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值