5个非常有意思的python代码,谁运行谁知道
Python 能做很多无聊,但有意思的事情,例如接下来的一些案例。
Python 整蛊程序
以下程序,不要发代码,要不实现不了你整蛊的目的。
要打包成一个 exe 程序,发给朋友才有意思。
使用 pip install pyinstaller。
打包命令如下:
pyinstaller -F 文件名.py
过程中如果出现 BUG(一般是编码错误),点击导航查看解决方案
有趣的代码一
while True: n = input("猜猜我在想啥?") print("猜错喽") 123
你的朋友将永远无法知道你在想什么。
当然我安装 360 之后,程序没了。
有趣的代码二
死命弹窗
import tkinter.messagebox while True: tkinter.messagebox.showerror(Windows 错误,你的电脑正在被攻击!) 1234
运行之后,很就刺激了,如果对方不会杀进程,更刺激。
有趣的代码三
调用默认浏览器,无限打开 ,让他爱上学习。
import webbrowser while True: webbrowser.open(www..net) 123
额,使用之后,阿喵自己的电脑死机了。
瞬间 CPU…
有趣的代码四
这个程序就动感多了,会随机出现弹窗。
import tkinter as tk import random import threading import time def boom(): window = tk.Tk() width = window.winfo_screenwidth() height = window.winfo_screenheight() a = random.randrange(0, width) b = random.randrange(0, height) window.title(你是一个傻狍子) window.geometry("200x50" + "+" + str(a) + "+" + str(b)) tk.Label(window, text=你是一个傻狍子, bg=green, font=(宋体, 17), width=20, height=4).pack() window.mainloop() threads = [] for i in range(100): t = threading.Thread(target=boom) threads.append(t) time.sleep(0.1) threads[i].start() 12345678910111213141516171819202122232425
运行效果如下图所示,非常带劲,可以任意修改。
有趣的代码五
该程序在阿喵看来能排到第一,甚至可以和当下最火的枪茅台案例结合一下。
别运行,运行之后别怪我。
pyinstaller 编码 BUG 在使用 pyinstaller 进行打包 exe 的时候,会出现如下错误:
File "c:usersadministratorappdatalocalprogramspythonpython37libsite-packagesPyInstallerutilshooks\__init__.py", line 68, in __exec_python_cmd txt = exec_python(*cmd, env=pp_env) File "c:usersadministratorappdatalocalprogramspythonpython37libsite-packagesPyInstallercompat.py", line 526, in exec_python return exec_command(*cmdargs, **kwargs) File "c:usersadministratorappdatalocalprogramspythonpython37libsite-packagesPyInstallercompat.py", line 321, in exec_command out = out.decode(encoding) AttributeError: str object has no attribute decode 1234567
out = out.decode(encoding) # 改为 out = out
打包成功在 dist 文件中找寻 exe 程序即可。