小工具知识网

当前位置: 首页 > 行业知识 > Python恶搞代码

行业知识

Python恶搞代码

2026-11-08 02:15:09 来源:互联网转载

文章目录

  • 系列文章
  • 前言
    • Tkinter界面设计
    • Threading多线程
    • 恶搞代码
    • 完整代码
    • ��声

      系列文章

      序号文章目录直达链接
      表白系列
      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 tkinterroot = tkinter.Tk()label = tkinter.Label(root, text="Hello, World!")label.pack()root.mainloop()

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

      2. 简单的控件

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

      1. Label (标签)

      用于显示文本或图像。

      import tkinterroot = tkinter.Tk()label = tkinter.Label(root, text = "Hello World!")label.pack()root.mainloop()
      1. Button (按钮)

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

      import tkinterroot = tkinter.Tk()def buttonClicked():    print("Button clicked")button = tkinter.Button(root, text = "Click me", command = buttonClicked)button.pack()root.mainloop()
      1. Entry (输入框)

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

      import tkinterroot = 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()

      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 threadingimport queuequeue = 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 threadingvalue = threading.Value('i', 0)def myThread(value):    value.value += 1thread = 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

      尾声

      感谢支持吖!

上一篇:网站服务器查询地址怎么查?

下一篇:博图服务器怎么连接?