码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • python表白程序,无法拒绝


    在这里插入图片描述

    # coding=gbk
    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
        canvas = tk.Canvas(popup, bg='pink', highlightthickness=0)
        canvas.pack(expand=True, fill="both")
    
        # 创建Label并设置字体大小以铺满Canvas
        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
  • 相关阅读:
    第2篇 机器学习基础 —(1)机器学习概念和方式
    mac vscode xdebug 调试moodle
    【2023年11月第四版教材】第16章《采购管理》(第一部分)
    1 论文笔记:Efficient Trajectory Similarity Computation with ContrastiveLearning
    [Linux]进程间通信(进程间通信介绍 | 匿名管道 | 命名管道)
    Java中的异常体系
    【linux】基础IO+系统文件IO+文件描述符分配规则
    剑指offer(C++)-JZ50:第一个只出现一次的字符(算法-其他)
    CMU15-445 format\clang-format\clang-tidy 失败
    【Java面试题】DCL单例模式设计为什么需要volatile修饰实例对象
  • 原文地址:https://blog.csdn.net/weixin_52236586/article/details/134492781
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号