Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

The opening

Python can do a lot of boring, but interesting things, such as the following examples.

The following procedures, do not send code, or can not achieve the purpose of your prank.

Package it into an EXE program and send it to a friend.

Use PIP Install PyInstaller.

The package command is as follows:

Pyinstaller -f Filename.pyCopy the code

If there is a BUG (usually a coding error), click the navigation to see the solution

One of the boring programs

while True:
	n = input("Guess what I was thinking?")
	print("Guess wrong.")
Copy the code

Your friends will never know what you’re thinking.

Of course, after I installed the 360, the program was gone. If you are interested in learning about no-kill, you can like this article 100 times and eraser a Python no-kill tutorial.

The sky is blue and there are thousands of paper cranes outside the window

Boring program number two

Siming popup window

import tkinter.messagebox

while True:
    tkinter.messagebox.showerror('Windows error'.'Your computer is being attacked! ')
Copy the code

After running, very exciting, if the other side will not kill the process, even more exciting.The sky is blue and there are thousands of paper cranes outside the window

Boring program number three

Call the default browser, open CSDN unlimited, let him love learning.

import webbrowser
while True:
    webbrowser.open('www.csdn.net')
Copy the code

Well, after using it, eraser’s own computer crashed.

The instant CPU…The sky is blue and there are thousands of paper cranes outside the window

Boring program number four

This program is much more dynamic, will randomly pop up.

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('You are a stupid roe deer.')
    window.geometry("200x50" + "+" + str(a) + "+" + str(b))
    tk.Label(window, text='You are a stupid roe deer.', 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()
Copy the code

The running effect is shown in the picture below, which is very exciting and can be modified at will.The sky is blue and there are thousands of paper cranes outside the window

Boring program number five

The program could be no. 1 in erasers, and could even be combined with the current hot gun Maotai case.

import os
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 O888O Y888P Functions: 1. 2. """
print(a)

key = input("Please select :")

if key == "1":
     time.sleep(1.5)
     print('No reservation \n')
     time.sleep(3)
     print('It's okay. Give me a hug.')

else:
     print("In that case...)
     time.sleep(3)
     print("That you want the United States ~~~~~")
     os.system('shutdown -r -t 10')
time.sleep(10)
Copy the code

The sky is blue, there are thousands of paper cranes outside the window == Don’t run, run after don’t blame me.

Pyinstaller coding bugs

The following error occurs when using PyInstaller to package the EXE:

  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 68, in __exec_python_cmd
    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'
Copy the code

Screenshot below:Modify the following code as indicated by the BUG:

out = out.decode(encoding) # out = out
Copy the code

Package success indistLook in the filesexeProcedure.