import tkinter as tk
import random
import tkinter.messagebox as messagebox
root = tk.Tk()
root.attributes('-alpha', 0)
message = "做我女朋友好不好?"
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
def create_popup():
popup = tk.Toplevel(root)
popup.geometry("300x150")
popup.title("表白弹框")
popup.configure(bg='pink')
x = random.randint(0, screen_width - 300)
y = random.randint(0, screen_height - 150)
popup.geometry(f"+{x}+{y}")
canvas = tk.Canvas(popup, bg='pink', highlightthickness=0)
canvas.pack(expand=True, fill="both")
label = tk.Label(canvas, text=message, font=("Helvetica", 18), bg='pink', wraplength=260, justify="center")
canvas.create_window(150, 60, window=label)
button_frame = tk.Frame(canvas, bg='pink')
canvas.create_window(150, 110, window=button_frame)
agree_button = tk.Button(button_frame, text="同意", command=on_agree)
agree_button.pack(side="left", padx=20)
refuse_button = tk.Button(button_frame, text="拒绝", command=lambda: on_refuse(popup))
refuse_button.pack(side="left", padx=20)
popup.attributes('-topmost', True)
popup.protocol("WM_DELETE_WINDOW", lambda: on_close(popup))
def on_agree():
messagebox.showinfo("提示", "我喜欢你")
root.quit()
def on_refuse(popup):
popup.destroy()
create_popup()
def on_close(popup):
popup.destroy()
create_popup()
create_popup()
root.mainloop()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83