Ahhs
Ahhs
import tkinter as tk
from tkinter import ttk, font, messagebox, filedialog
from pywifi import PyWiFi, const, Profile
from tkhtmlview import HTMLLabel
from tkinterweb import HtmlFrame
from PIL import Image, ImageTk
from time import strftime
import time
import requests
import pygame
import random
import os
import cv2
API_KEY = 'AIzaSyA2oEtG3QrtgtF44z5gqt-lBtwtNXYvOro'
SEARCH_ENGINE_ID = '60aaa3632bab04409'
class SBLOS:
def __init__(self):
self.root = tk.Tk()
self.root.title("SBL-OS")
self.root.geometry("900x700")
self.root.configure(bg="#00FFFF")
self.root.after(10000, self.button_clicked)
self.root.mainloop()
def button_clicked(self):
taskbar = tk.Frame(self.root, bg="gray", height=40)
taskbar.pack(side=tk.BOTTOM, fill=tk.X)
apps = [
("SBL-Browser", self.open_sbl_browser),
("Notepad", self.open_notepad),
("Music", self.open_music),
("SBL-Pong", self.open_pp),
("SBL-Snake", self.open_snake_game),
("Video Player", self.open_vp)
]
def update_time(self):
current_time = time.strftime('%H:%M:%S')
self.clock_label.config(text=current_time)
self.root.after(1000, self.update_time)
def open_wifi_manager(self):
wifi_manager = tk.Toplevel(self.root)
wifi_manager.title("Wi-Fi Manager")
wifi_manager.geometry("400x300")
self.wifi = PyWiFi()
self.iface = self.wifi.interfaces()[0]
self.networks_listbox = tk.Listbox(wifi_manager)
self.networks_listbox.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
def scan_networks(self):
self.iface.scan()
time.sleep(2)
scan_results = self.iface.scan_results()
self.networks_listbox.delete(0, tk.END)
seen_ssids = set()
def connect_to_network(self):
selected_network = self.networks_listbox.get(tk.ACTIVE)
if not selected_network:
messagebox.showwarning("No Network Selected", "Please select a network
to connect to.")
return
password = self.ask_for_password()
if password is None:
return
profile = Profile()
profile.ssid = selected_network
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = password
self.iface.remove_all_network_profiles()
temp_profile = self.iface.add_network_profile(profile)
self.iface.connect(temp_profile)
time.sleep(5)
if self.iface.status() == const.IFACE_CONNECTED:
messagebox.showinfo("Connected", f"Connected to {selected_network}")
else:
messagebox.showerror("Connection Failed", f"Failed to connect to
{selected_network}")
def disconnect_network(self):
self.iface.disconnect()
time.sleep(2)
if self.iface.status() != const.IFACE_DISCONNECTED:
messagebox.showerror("Disconnection Failed", "Failed to disconnect from
the network.")
else:
messagebox.showinfo("Disconnected", "Disconnected from the network.")
def ask_for_password(self):
password_window = tk.Toplevel(self.root)
password_window.title("Enter Password")
password_window.geometry("300x100")
def submit_password():
self.password = password_entry.get()
password_window.destroy()
tk.Button(password_window, text="Submit",
command=submit_password).pack(pady=5)
password_window.wait_window()
return self.password
def open_sbl_browser(self):
class WebBrowser(tk.Tk):
def __init__(self):
super().__init__()
self.title("SBL-Browser V2")
self.geometry("800x600")
def go_back(self):
if self.history:
previous_url = self.history.pop()
self.current_page = previous_url
self.url_entry.delete(0, tk.END)
self.url_entry.insert(0, previous_url)
self.load_url(previous_url)
def google_search(self):
query = self.url_entry.get()
url = f"https://www.googleapis.com/customsearch/v1?
key={API_KEY}&cx={SEARCH_ENGINE_ID}&q={query}"
try:
response = requests.get(url)
data = response.json()
if 'items' in data:
html_content = '<h1>Search Results</h1>'
for item in data['items']:
title = item.get('title')
link = item.get('link')
snippet = item.get('snippet')
html_content += f'<h3><a href="{link}"
target="_self">{title}</a></h3><p>{snippet}</p>'
self.html_frame.load_html(html_content)
else:
self.html_frame.load_html("<h1>No results found.</h1>")
except Exception as e:
self.html_frame.load_html(f"<h1>Error occurred: {e}</h1>")
if __name__ == "__main__":
app = WebBrowser()
app.mainloop()
def open_notepad(self):
def new_file():
if text.get("1.0", tk.END) != "\n":
if messagebox.askyesno("Save Changes", "Do you want to save
changes?"):
save_file()
text.delete("1.0", tk.END)
def open_file():
file_path = filedialog.askopenfilename(defaultextension=".txt",
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if file_path:
with open(file_path, "r") as file:
text.delete("1.0", tk.END)
text.insert("1.0", file.read())
root.title(f"Notepad - {file_path}")
def save_file():
file_path = filedialog.asksaveasfilename(defaultextension=".txt",
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if file_path:
with open(file_path, "w") as file:
file.write(text.get("1.0", tk.END))
root.title("Notepad - {file_path}")
root = tk.Tk()
root.title("Notepad")
menu = tk.Menu(root)
root.config(menu=menu)
file_menu = tk.Menu(menu)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="New", command=new_file)
file_menu.add_command(label="Open", command=open_file)
file_menu.add_command(label="Save", command=save_file)
file_menu.add_separator()
root.mainloop()
def open_music(self):
pygame.mixer.init()
tracks = [
"Soham Bhole - FUN",
"Soham Bhole - More Fun",
]
def play_song(track):
if track == "Soham Bhole - FUN":
pygame.mixer.music.load("Soham Bhole - FUN.mp3")
pygame.mixer.music.play(-1)
else:
pygame.mixer.music.load("Soham Bhole - More Fun.mp3")
pygame.mixer.music.play(-1)
def stop_song():
pygame.mixer.music.stop()
root = tk.Tk()
root.title("Music App")
root.mainloop()
def open_snake_game(self):
WIDTH = 400
HEIGHT = 400
SNAKE_SIZE = 20
SNAKE_SPEED = 150
BG_COLOR = "black"
SNAKE_COLOR = "green"
FOOD_COLOR = "red"
class SimpleSnakeGame:
def __init__(self, root):
self.root = root
self.root.title("Snake Game")
self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT,
bg=BG_COLOR)
self.canvas.pack()
self.draw_snake()
self.draw_food()
self.root.bind("<KeyPress>", self.change_direction)
self.update_snake()
def spawn_food(self):
x = random.randint(0, (WIDTH - SNAKE_SIZE) // SNAKE_SIZE) *
SNAKE_SIZE
y = random.randint(0, (HEIGHT - SNAKE_SIZE) // SNAKE_SIZE) *
SNAKE_SIZE
return (x, y)
def draw_snake(self):
self.canvas.delete("snake")
for segment in self.snake:
self.canvas.create_rectangle(segment[0], segment[1], segment[0]
+ SNAKE_SIZE, segment[1] + SNAKE_SIZE, fill=SNAKE_COLOR, tag="snake")
def draw_food(self):
self.canvas.delete("food")
self.canvas.create_rectangle(self.food[0], self.food[1],
self.food[0] + SNAKE_SIZE, self.food[1] + SNAKE_SIZE, fill=FOOD_COLOR, tag="food")
def update_snake(self):
if not self.running:
return
if new_head == self.food:
self.snake.append(self.snake[-1])
self.food = self.spawn_food()
self.draw_food()
self.draw_snake()
self.root.after(SNAKE_SPEED, self.update_snake)
def open_pp(self):
WIDTH = 600
HEIGHT = 400
PADDLE_WIDTH = 10
PADDLE_HEIGHT = 100
BALL_SIZE = 20
BALL_SPEED_X = 4
BALL_SPEED_Y = 4
PADDLE_SPEED = 20
class PingPongGame:
def __init__(self, root):
self.root = root
self.root.title("Ping Pong Game")
self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT,
bg="black")
self.canvas.pack()
self.ball_speed_x = BALL_SPEED_X
self.ball_speed_y = BALL_SPEED_Y
self.root.bind("<KeyPress>", self.on_key_press)
self.root.bind("<KeyRelease>", self.on_key_release)
self.left_paddle_up = False
self.left_paddle_down = False
self.right_paddle_up = False
self.right_paddle_down = False
self.update_game()
def update_game(self):
self.move_paddles()
self.move_ball()
self.check_collisions()
self.root.after(20, self.update_game)
def move_paddles(self):
if self.left_paddle_up:
self.canvas.move(self.left_paddle, 0, -PADDLE_SPEED)
if self.left_paddle_down:
self.canvas.move(self.left_paddle, 0, PADDLE_SPEED)
if self.right_paddle_up:
self.canvas.move(self.right_paddle, 0, -PADDLE_SPEED)
if self.right_paddle_down:
self.canvas.move(self.right_paddle, 0, PADDLE_SPEED)
self.canvas.move(self.left_paddle, 0, 0)
self.canvas.move(self.right_paddle, 0, 0)
self.ensure_paddle_bounds(self.left_paddle)
self.ensure_paddle_bounds(self.right_paddle)
def move_ball(self):
self.canvas.move(self.ball, self.ball_speed_x, self.ball_speed_y)
x1, y1, x2, y2 = self.canvas.coords(self.ball)
def check_collisions(self):
x1, y1, x2, y2 = self.canvas.coords(self.ball)
bx1, by1, bx2, by2 = self.canvas.coords(self.left_paddle)
rx1, ry1, rx2, ry2 = self.canvas.coords(self.right_paddle)
if x1 <= bx2 and x2 >= bx1 and y1 <= by2 and y2 >= by1:
self.ball_speed_x = -self.ball_speed_x
if x1 <= rx2 and x2 >= rx1 and y1 <= ry2 and y2 >= ry1:
self.ball_speed_x = -self.ball_speed_x
root = tk.Tk()
game = PingPongGame(root)
root.mainloop()
def open_vp(self):
class VideoPlayer:
def __init__(self, root):
self.root = root
self.root.title("Video Player")
self.video_source = None
self.video_cap = None
self.is_playing = False
self.update_interval = 30
def open_video(self):
self.video_source = filedialog.askopenfilename(filetypes=[("Video
files", "*.mp4;*.avi;*.mov")])
if self.video_source:
self.video_cap = cv2.VideoCapture(self.video_source)
self.is_playing = False
self.update_frame()
def play_video(self):
if self.video_source and not self.is_playing:
self.is_playing = True
self.update_frame()
def stop_video(self):
self.is_playing = False
if self.video_cap:
self.video_cap.release()
def update_frame(self):
if self.is_playing and self.video_cap.isOpened():
ret, frame = self.video_cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame)
image_tk = ImageTk.PhotoImage(image=image)
self.canvas.create_image(0, 0, anchor=tk.NW,
image=image_tk)
self.canvas.image_tk = image_tk
self.root.after(self.update_interval, self.update_frame)
else:
self.is_playing = False
self.video_cap.release()
if __name__ == "__main__":
root = tk.Tk()
player = VideoPlayer(root)
root.mainloop()
os = SBLOS()