Skip to content

Commit 80c8141

Browse files
Add files via upload
1 parent 5f7d8ce commit 80c8141

34 files changed

Lines changed: 977 additions & 0 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# pip install pygal
2+
3+
import pygal
4+
5+
6+
bar = pygal.Bar()
7+
bar.title = 'Simple Animated Bar'
8+
bar.add('A', [1, 3, 5])
9+
bar.add('B', [5, 2, 4])
10+
bar.redner_in_browser()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from tkinter import *
2+
3+
4+
# root class
5+
class App(Frame):
6+
def __init__(self, win):
7+
super().__init__(win)
8+
self.win = win
9+
self.icon_visible = False
10+
11+
self.lb_icon = Label(self.win, text="⚠️", font=("Cambria", 48, "bold"), fg="red", justify="center")
12+
self.lb_icon.place(relx=0.5, rely=0.5, anchor="center")
13+
14+
self.blink_icon()
15+
16+
17+
def blink_icon(self):
18+
if self.icon_visible:
19+
self.lb_icon.config(fg="#F0F0ED")
20+
self.icon_visible = False
21+
else:
22+
self.lb_icon.config(fg="red")
23+
self.icon_visible = True
24+
self.win.after(600, self.blink_icon)
25+
26+
27+
# root
28+
if __name__ == '__main__':
29+
win = Tk()
30+
win.title('Icon Animation')
31+
32+
w, h = 850, 500
33+
sw = win.winfo_screenwidth()
34+
sh = win.winfo_screenheight()
35+
x, y = (sw - w) // 2, (sh - h) // 2
36+
win.geometry(f'{w}x{h}+{x}+{y-40}')
37+
38+
app = App(win)
39+
win.mainloop()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from tkinter import *
2+
3+
4+
# root class
5+
class App(Frame):
6+
def __init__(self, win):
7+
super().__init__(win)
8+
self.win = win
9+
self.text = "Not Free — This is a paid project, available after purchase!"
10+
self.index = 0
11+
12+
self.lb_text = Label(self.win, text=self.text, font=("Cambria", 19, "bold"), fg="red", wraplength=700, justify="center")
13+
self.lb_text.place(relx=0.5, rely=0.5, anchor="center")
14+
15+
self.animate_text()
16+
17+
18+
def animate_text(self):
19+
if self.index < len(self.text):
20+
self.lb_text.config(text=self.text[:self.index + 1])
21+
self.index += 1
22+
self.win.after(70, self.animate_text)
23+
else:
24+
self.win.after(2000, self.restart_animation)
25+
26+
27+
def restart_animation(self):
28+
self.index = 0
29+
self.lb_text.config(text="")
30+
self.win.after(300, self.animate_text)
31+
32+
33+
# root
34+
if __name__ == '__main__':
35+
win = Tk()
36+
win.title('Text Animation')
37+
38+
w, h = 850, 500
39+
sw = win.winfo_screenwidth()
40+
sh = win.winfo_screenheight()
41+
x, y = (sw - w) // 2, (sh - h) // 2
42+
win.geometry(f'{w}x{h}+{x}+{y-40}')
43+
44+
app = App(win)
45+
win.mainloop()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import tkinter as tk
2+
3+
4+
UNLOCK_KEY = '12345'
5+
MAX_ATTEMPTS = 3
6+
ATTEMPT_COUNT = 0
7+
8+
def handle_unlock_request(event):
9+
global ATTEMPT_COUNT
10+
ATTEMPT_COUNT += 1
11+
12+
if unlock_entry.get().strip() == UNLOCK_KEY:
13+
root.destroy()
14+
elif ATTEMPT_COUNT >= MAX_ATTEMPTS:
15+
root.destroy()
16+
else: unlock_entry.delete(0, tk.END)
17+
18+
19+
root = tk.Tk()
20+
21+
root.title('Self Destroy')
22+
root.attributes('-alpha', 0.8) # 80% transparent
23+
root.attributes('-fullscreen', True) # show the window as full-screen
24+
root.attributes('-topmost', True) # always show window in the top
25+
root.protocol('WM_DELETE_WINDOW', lambda: None) # cannot close window/disable close button
26+
27+
28+
unlock_entry = tk.Entry(root, show='*', font=(None, 20, 'bold'), width=20, justify='center', relief=tk.FLAT)
29+
unlock_entry.place(relx=0.5, rely=0.5, anchor='center')
30+
unlock_entry.bind('<Return>', handle_unlock_request) # bind enter/return key
31+
32+
33+
root.resizable(0, 0)
34+
root.mainloop()

practice-code/0353_pdf_to_docx.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# pip install pdfplumber
2+
# pip install python-docx
3+
4+
import pdfplumber
5+
from docx import Document
6+
7+
8+
pdf = pdfplumber.open('<file_name>.pdf')
9+
doc = Document()
10+
11+
for page in pdf.pages:
12+
text = page.extract_text()
13+
if text:
14+
doc.add_paragraph(text)
15+
16+
doc.save('<file_name>.docx')
17+
pdf.close()
18+
19+
print("Text extracted and saved!")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import hashlib
2+
3+
4+
def file_hash(file_path, algo='sha256'):
5+
h = hashlib.new(algo)
6+
with open(file_path, 'rb') as f:
7+
while chunk := f.read(8192):
8+
h.update(chunk)
9+
return h.hexdigest()
10+
11+
12+
file_path = '<file_name>.txt'
13+
print('SHA-256 Hash:', file_hash(file_path))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import hashlib
2+
3+
4+
file = '<file_name>.txt'
5+
6+
with open(file, 'rb') as f:
7+
hash = hashlib.md5(f.read()).hexdigest()
8+
9+
print('MD5:', hash)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
4+
PATH = r'C:\Downloads' # directory path
5+
6+
files = 0
7+
dirs = 0
8+
9+
for root, dirnames, filenames in os.walk(PATH):
10+
dirs += len(dirnames)
11+
files += len(filenames)
12+
13+
print('Files:', files)
14+
print('Directories:', dirs)
15+
print('Total:', files + dirs)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# pip install psutil
2+
3+
import time
4+
import psutil
5+
6+
7+
before = psutil.net_io_counters()
8+
time.sleep(1)
9+
after = psutil.net_io_counters()
10+
11+
download = after.bytes_recv - before.bytes_recv
12+
upload = after.bytes_sent - before.bytes_sent
13+
14+
print('Download Speed:', download, 'Bytes/sec')
15+
print('Upload Speed:', upload, 'Bytes/sec')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pip install psutil
2+
3+
import psutil
4+
5+
6+
cpu_percent = psutil.cpu_percent(interval=1)
7+
8+
print('CPU Usage:', cpu_percent, '%')

0 commit comments

Comments
 (0)