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无限弹窗恶搞代码吧!每天写一些有趣的小程序,带你成为一个有趣的程序员!

Tkinter界面设计

1. 创建一个简单的界面

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

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

完整的程序:

import tkinter

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

这个程序会创建一个带有 “Hello, World!” 标签的窗口,并且会一直保持在屏幕上直到退出程序。

2. 简单的控件

在 Tkinter 中,有许多控件可用来创建图形用户界面。下面是一些简单的控件及其用法:

  1. Label (标签)

用于显示文本或图像。

import tkinter

root = tkinter.Tk()

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

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

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

import tkinter

root = tkinter.Tk()

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

button = tkinter.Button(root, text = "Click me", command = buttonClicked)
button.pack()

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

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

import tkinter

root = tkinter.Tk()

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

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

button = tkinter.Button(root, text = "Submit", command = buttonClicked)
button.pack()

root.mainloop()

以上控件都是 Tkinter 中的基本控件,掌握了这些,就可以开始创建简单的GUI程序了。

Threading多线程

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

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

可以使用 Thread 类创建一个线程。需要给类的构造函数传递一个可调用的函数作为参数,这个函数将会在线程中运行。

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

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

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

使用 Queue:

import threading
import queue

queue = queue.Queue()

def myThread(queue, message):
    queue.put(message)

thread = threading.Thread(target=myThread, args=(queue, 'Hello, World'))
thread.start()

message = queue.get()
print(message)

使用 Value:

import threading

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

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

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

print(value.value)

以上是一些线程使用方法和函数的示例。需要注意的是,多线程程序的正确性可能会受到许多因素的影响,比如数据竞争、死锁、饥饿等等,需要仔细考虑和设计线程间的交互机制。

恶搞代码

在简单了解了Tkinter界面设计以及Threading多线程后,我们就可以写一个恶搞好友的程序啦!

1. 恶作剧界面

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

def Death():
    root=tk.Tk()
    width=200
    height=50
    screenwidth=root.winfo_screenwidth()
    screenheight=root.winfo_screenheight()
    x=ra.randint(0,screenwidth)
    y=ra.randint(0,screenheight)
    root.title("警告")
    root.geometry("%dx%d+%d+%d"%(width,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循环中的层数设置适当,避免程序复杂度过大导致系统崩溃(以下代码将for循环设置了十层,会产生10个小窗体)

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

完整代码

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

尾声

感谢支持吖!

  • 161
    点赞
  • 347
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 95
    评论
Python 烟花代码是一种用Python编写的模拟烟花爆炸效果的程序。它通过绘制图形和模拟物理效果来实现烟花的动态效果。 以下是一个简单的Python烟花代码示例: ```python import random import turtle # 创建画布 canvas = turtle.Screen() canvas.bgcolor("black") # 创建烟花粒子类 class Particle(turtle.Turtle): def __init__(self, color): turtle.Turtle.__init__(self) self.shape("circle") self.color(color) self.penup() def launch(self): self.goto(0, -200) self.setheading(random.randint(0, 360)) self.speed(10) self.showturtle() def explode(self): self.hideturtle() for _ in range(20): self.color(random.choice(["red", "orange", "yellow", "green", "blue", "purple"])) self.goto(random.randint(-300, 300), random.randint(-300, 300)) self.showturtle() # 创建烟花管理类 class FireworkManager: def __init__(self): self.particles = [] def launch_firework(self): particle = Particle("white") particle.launch() self.particles.append(particle) def explode_firework(self): for particle in self.particles: particle.explode() # 创建烟花管理器对象 manager = FireworkManager() # 发射烟花 manager.launch_firework() # 等待一段时间后,烟花爆炸 turtle.delay(1000) manager.explode_firework() # 关闭画布 turtle.done() ``` 这段代码使用了Python的turtle库来绘制图形,并通过模拟粒子的运动和爆炸效果来实现烟花的动态效果。代码中定义了一个烟花粒子类Particle,以及一个烟花管理类FireworkManager。通过调用FireworkManager的launch_firework方法来发射烟花,然后等待一段时间后调用explode_firework方法使烟花爆炸。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 95
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Want595

感谢小伙伴的支持!

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

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

打赏作者

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

抵扣说明:

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

余额充值