here is code that hide the windows window from screen recording & screen share. please don't use it for interview cheating.
import tkinter as tk
from tkinter import Listbox, END
import ctypes
import json
import os
from datetime import datetime
# ---------------- FILE ----------------
chat_file = "chat_history.json"
def load_chat():
if os.path.exists(chat_file):
with open(chat_file, "r") as f:
return json.load(f)
return []
def save_chat(data):
with open(chat_file, "w") as f:
json.dump(data, f, indent=4)
chat_data = load_chat()
# ---------------- WINDOW ----------------
root = tk.Tk()
root.overrideredirect(True)
root.attributes("-topmost", True)
root.geometry("340x450+200+200")
root.configure(bg="#1e1e1e")
root.update()
# ---------------- WINDOWS API ----------------
hwnd = ctypes.windll.user32.GetParent(root.winfo_id())
GWL_EXSTYLE = -20
WS_EX_LAYERED = 0x80000
styles = ctypes.windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
ctypes.windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, styles | WS_EX_LAYERED)
ctypes.windll.user32.SetLayeredWindowAttributes(hwnd, 0, 255, 0x2)
try:
WDA_EXCLUDEFROMCAPTURE = 0x11
ctypes.windll.user32.SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE)
except:
pass
# ---------------- TOOLBAR ----------------
toolbar = tk.Frame(root, bg="#0f0f0f", height=28)
toolbar.pack(fill=tk.X)
title = tk.Label(toolbar, text="Mini Chat", fg="white", bg="#0f0f0f")
title.pack(side=tk.LEFT, padx=8)
# Close button
def close_app():
root.destroy()
close_btn = tk.Button(
toolbar,
text="✕",
command=close_app,
bg="#0f0f0f",
fg="white",
bd=0,
activebackground="red",
activeforeground="white"
)
close_btn.pack(side=tk.RIGHT, padx=5)
# Drag logic (toolbar only)
def start_move(event):
root._x = event.x
root._y = event.y
def do_move(event):
x = root.winfo_pointerx() - root._x
y = root.winfo_pointery() - root._y
root.geometry(f"+{x}+{y}")
toolbar.bind("<Button-1>", start_move)
toolbar.bind("<B1-Motion>", do_move)
title.bind("<Button-1>", start_move)
title.bind("<B1-Motion>", do_move)
# ---------------- CHAT AREA ----------------
chat_list = Listbox(root, bg="#2b2b2b", fg="white", bd=0, highlightthickness=0)
chat_list.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
for msg in chat_data:
chat_list.insert(END, msg)
# ---------------- INPUT ----------------
entry = tk.Entry(root, bg="#3a3a3a", fg="white", bd=0)
entry.pack(fill=tk.X, padx=5, pady=5, ipady=6)
def send_message(event=None):
msg = entry.get().strip()
if msg:
time = datetime.now().strftime("%H:%M")
full_msg = f"[{time}] You: {msg}"
chat_data.append(full_msg)
save_chat(chat_data)
chat_list.insert(END, full_msg)
chat_list.yview(END)
entry.delete(0, END)
entry.bind("<Return>", send_message)
# ---------------- RESIZE ----------------
resizer = tk.Frame(root, bg="#444444", cursor="size_nw_se", width=10, height=10)
resizer.place(relx=1.0, rely=1.0, anchor="se")
def start_resize(event):
root._rw = root.winfo_width()
root._rh = root.winfo_height()
root._rx = event.x
root._ry = event.y
def do_resize(event):
w = root._rw + (event.x - root._rx)
h = root._rh + (event.y - root._ry)
if w > 220 and h > 250:
root.geometry(f"{w}x{h}")
resizer.bind("<Button-1>", start_resize)
resizer.bind("<B1-Motion>", do_resize)
# ---------------- RUN ----------------
root.mainloop()
Top comments (0)