5 个无聊透顶的Python 程序(文末送书)
exe
程序,发给朋友才有意思。pip install pyinstaller
。无聊程序之一
n = input('猜猜我在想啥?')
print('猜错喽')
无聊程序之二
死命弹窗
while True:
tkinter.messagebox.showerror('Windows 错误','你的电脑正在被攻击!')
无聊程序之三
while True:
webbrowser.open('www.csdn.net')
无聊程序之四
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()
无聊程序之五
该程序在我看来能排到第一,甚至可以和当下最火的抢茅台案例结合一下。
import time
a = '''
oooo oooooooooo. .oooooo..o oooo o8o oooo oooo
`888 `888' `Y8b d8P' `Y8 `888 `'' `888 `888
888 888 888 Y88bo. .ooooo. .ooooo. 888 oooo oooo 888 888
888 888 888 `'Y8888o. d88' `88b d88' `'Y8 888 .8P' `888 888 888
888 888 888 8888888 `'Y88b 888ooo888 888 888888. 888 888 888
888 888 d88' oo .d8P 888 .o 888 .o8 888 `88b. 888 888 888
.o. 88P o888bood8P' 8''88888P' `Y8bod8P' `Y8bod8P' o888o o888o o888o o888o o888o
`Y888P
功能列表:
1.预约商品
2.秒杀抢购商品
'''
print(a)
key = input('请选择:')
if key == '1':
time.sleep(1.5)
print('没有预约到\n')
time.sleep(3)
print('没事的,来抱一哈\n')
else:
print('既然如此...')
time.sleep(3)
print('那你想得美~~~~~')
os.system('shutdown -r -t 10')
time.sleep(10)
pyinstaller 编码 BUG
在使用 pyinstaller
进行打包 exe 的时候,会出现如下错误:
txt = exec_python(*cmd, env=pp_env)
File 'c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\compat.py', line 526, in exec_python
return exec_command(*cmdargs, **kwargs)
File 'c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\compat.py', line 321, in exec_command
out = out.decode(encoding)
AttributeError: 'str' object has no attribute 'decode'
截图如下:
out = out.decode(encoding) # 改为 out = out
打包成功在 dist
文件中找寻 exe
程序即可。
留言送书
2021,最值得期待的Python进阶宝典《Effective Python》第二版中文版,来咯!
作者将整个Python开发界的各种经验,全都浓缩到了一本书中,本书可以帮你掌握真正的Pythonic编程方式,令你能够完全发挥出Python语言的强大功能,并写出健壮而高效的代码。第二版代码基于Python3.X重写,新增30%内容,示例代码提供下载!