Python恶搞代码

在这里插入图片描述

系列文章

序号文章目录直达链接
表白系列
1无法拒绝的表白界面https://want595.blog.csdn.net/article/details/134744894
2满屏飘字表白代码https://want595.blog.csdn.net/article/details/135037388
3无限弹窗表白代码https://want595.blog.csdn.net/article/details/134744711
4李峋同款可写字版跳动的爱心https://want595.blog.csdn.net/article/details/134744191
5流星雨https://want595.blog.csdn.net/article/details/134747408
6漂浮爱心https://want595.blog.csdn.net/article/details/134744929
7爱心光波https://want595.blog.csdn.net/article/details/134747365
8玫瑰花https://want595.blog.csdn.net/article/details/134747447
节日系列
1新春/跨年烟花秀(2022)https://want595.blog.csdn.net/article/details/128727394
烟花秀(2023)https://want595.blog.csdn.net/article/details/135042880
粒子烟花https://want595.blog.csdn.net/article/details/136029420
2圣诞节圣诞礼物https://want595.blog.csdn.net/article/details/135336583
圣诞树(2022)https://want595.blog.csdn.net/article/details/128428985
绿色圣诞树(2023)https://want595.blog.csdn.net/article/details/135048607
粉色圣诞树(2023)https://want595.blog.csdn.net/article/details/135043042
3冬至大雪纷飞https://want595.blog.csdn.net/article/details/128806017
4生日生日蛋糕https://want595.blog.csdn.net/article/details/128739755
5儿童节五彩气球https://want595.blog.csdn.net/article/details/128741043
6国庆节国庆祝福https://want595.blog.csdn.net/article/details/128740923
7万圣节万圣礼物https://want595.blog.csdn.net/article/details/128734395
8愚人节愚人代码https://want595.blog.csdn.net/article/details/128696990
9中秋节浪漫星空https://want595.blog.csdn.net/article/details/128737284
10植树节樱花树https://want595.blog.csdn.net/article/details/128700178
动漫系列
1名侦探柯南系列柯南https://want595.blog.csdn.net/article/details/134777613
2喜羊羊与灰太狼系列喜羊羊https://want595.blog.csdn.net/article/details/134778583
懒羊羊https://want595.blog.csdn.net/article/details/134847642
灰太狼https://want595.blog.csdn.net/article/details/135335303
小灰灰https://want595.blog.csdn.net/article/details/135335445
小香香https://want595.blog.csdn.net/article/details/135056783
3海绵宝宝系列海绵宝宝https://want595.blog.csdn.net/article/details/134847364
4哆啦A梦系列哆啦A梦https://want595.blog.csdn.net/article/details/135037884
5HelloKitty系列hellokittyhttps://want595.blog.csdn.net/article/details/135337732
6Tom&Jerry系列Tom&Jerryhttps://want595.blog.csdn.net/article/details/135337775
7草莓熊系列草莓熊https://want595.blog.csdn.net/article/details/135337832
8皮卡丘系列迷你皮卡丘https://want595.blog.csdn.net/article/details/135337911
高级皮卡丘https://want595.blog.csdn.net/article/details/135337937
豪华皮卡丘https://want595.blog.csdn.net/article/details/135337947
炫酷系列
1  一闪一闪亮星星系列张万森下雪了https://want595.blog.csdn.net/article/details/135336915
一闪一闪亮星星https://want595.blog.csdn.net/article/details/135337049
2代码雨https://want595.blog.csdn.net/article/details/135054341
3七彩花朵https://want595.blog.csdn.net/article/details/135056670
43D星空https://want595.blog.csdn.net/article/details/135056516
5金榜题名https://want595.blog.csdn.net/article/details/135056150
6满天星https://want595.blog.csdn.net/article/details/135056305
……

前言

快来领取python无限弹窗恶搞代码吧!每天写一些有趣的小程序,带你成为一个有趣的程序员!

技术需求

1. 创建一个简单的界面

Tkinter 是 Python 标准库中的一个 GUI(图形用户界面)模块,用于创建窗口、标签、按钮、菜单等交互式界面。以下是 Tkinter 中一些基本函数的使用方法。

  1. 导入 Tkinter 包:
import tkinter as tk
  1. 创建主窗口:
root = tk.Tk()
  1. 创建标签:
label = tk.Label(root, text="Hello, World!")
  1. 显示标签:
label.pack()
  1. 进入主循环:
root.mainloop()

完整的程序示例:

import tkinter as tk

root = tk.Tk()
label = tk.Label(root, text="Hello, World!")
label.pack()
root.mainloop()

此程序将创建一个带有 “Hello, World!” 标签的窗口,并保持显示直到程序退出。

2. 简单的控件

Tkinter 提供了多种控件来构建图形用户界面。以下是一些基本控件及其用法:

  1. Label (标签)

用于显示文本或图像。

import tkinter as tk

root = tk.Tk()

label = tk.Label(root, text="Hello World!")
label.pack()

root.mainloop()
  1. Button (按钮)

用于执行操作或触发事件。

import tkinter as tk

root = tk.Tk()

def button_clicked():
    print("Button clicked")

button = tk.Button(root, text="Click me", command=button_clicked)
button.pack()

root.mainloop()
  1. Entry (输入框)

用于获取用户的文本输入。

import tkinter as tk

root = tk.Tk()

entry = tk.Entry(root)
entry.pack()

def submit():
    print("The text entered is:", entry.get())

button = tk.Button(root, text="Submit", command=submit)
button.pack()

root.mainloop()

掌握这些基本控件后,即可开始创建简单的 GUI 程序。

Threading 多线程

在 Python 中,可以使用 threading 模块来创建和管理线程。线程是程序执行流的最小单元,所有线程共享同一份数据。以下是一些简单的 threading 使用方法和函数。

  1. 导入 threading 模块
import threading
  1. 创建线程

使用 Thread 类创建一个线程,需传递一个可调用的函数作为参数,该函数将在新线程中运行。

def my_thread():
    print("Thread is running")

thread = threading.Thread(target=my_thread)
thread.start()
  1. 线程间通信

可以通过队列(Queue)和共享内存(Value 和 Array)等机制在线程间传递数据。

使用 Queue:

import threading
import queue

q = queue.Queue()

def my_thread(q, message):
    q.put(message)

thread = threading.Thread(target=my_thread, args=(q, 'Hello, World'))
thread.start()

message = q.get()
print(message)

使用 Value:

import threading

value = threading.Value('i', 0)

def increment_value(value):
    value.value += 1

thread = threading.Thread(target=increment_value, args=(value,))
thread.start()

print(value.value)

以上示例展示了线程的基本使用方法和函数。需要注意的是,多线程程序可能会遇到数据竞争、死锁等问题,需要仔细设计线程间的交互机制。

恶搞代码

了解了 Tkinter 界面设计和 Threading 多线程后,可以编写一个恶搞好友的程序。

1. 恶作剧界面

以下程序实现了一个简单的恶搞界面:

import tkinter as tk
import random as ra
import time as ti
import threading as td

def death_window():
    root = tk.Tk()
    width = 200
    height = 50
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    x = ra.randint(0, screenwidth - width)
    y = ra.randint(0, screenheight - height)
    root.title("警告")
    root.geometry(f"{width}x{height}+{x}+{y}")
    tk.Label(root, text='你的电脑已中毒!', fg='white', bg='black', font=("Comic Sans MS", 15), width=30, height=5).pack()
    root.mainloop()

2. 恶搞界面的数量

建议适当设置 for 循环层数,避免程序复杂度过大导致系统崩溃(以下代码设置了十层,将产生 10 个小窗体):

def start_joke():
    for i in range(10):
        t = td.Thread(target=death_window)
        ti.sleep(0.1)
        t.start()

完整代码

https://want595.blog.csdn.net/article/details/128696990

尾声

感谢支持吖!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Want595

感谢小伙伴的支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值