0% found this document useful (0 votes)
10 views11 pages

Ahhs

The document outlines the implementation of a graphical user interface (GUI) application called SBL-OS using Python's Tkinter library. It includes various functionalities such as a web browser, notepad, music player, and games like Snake and Ping Pong, along with a Wi-Fi manager for network scanning and connection. The application is designed to provide a user-friendly experience with features like real-time clock updates and interactive elements.

Uploaded by

iuero889y17981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Ahhs

The document outlines the implementation of a graphical user interface (GUI) application called SBL-OS using Python's Tkinter library. It includes various functionalities such as a web browser, notepad, music player, and games like Snake and Ping Pong, along with a Wi-Fi manager for network scanning and connection. The application is designed to provide a user-friendly experience with features like real-time clock updates and interactive elements.

Uploaded by

iuero889y17981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

#DISCLAIMER: GAMES TAKEN FROM EXTERNAL SOURCES

#MADE BY SOHAM FROM SOHAM BHOLE LLC

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.frame = tk.Frame(self.root, bg="#00FFFF")


self.frame.pack(expand=True)

self.loading_label = tk.Label(self.frame, text="SBL-OS VERSION 1.0",


font=("Helvetica", 24, "bold"), fg="#004C4C", bg="#00FFFF")
self.loading_label.pack(pady=20)

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)
]

for text, command in apps:


button = tk.Button(taskbar, text=text, command=command, bg="black",
fg="white")
button.pack(side=tk.LEFT, padx=5, pady=5)

wifi_button = tk.Button(taskbar, text="Wi-Fi",


command=self.open_wifi_manager, bg="black", fg="white")
wifi_button.pack(side=tk.RIGHT, padx=5, pady=5)
self.clock_label = tk.Label(taskbar, text="", bg="gray", fg="white")
self.clock_label.pack(side=tk.RIGHT, padx=5)
self.update_time()

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]

scan_button = tk.Button(wifi_manager, text="Scan Networks",


command=self.scan_networks, bg="black", fg="white")
scan_button.pack(pady=10)

self.networks_listbox = tk.Listbox(wifi_manager)
self.networks_listbox.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)

connect_button = tk.Button(wifi_manager, text="Connect",


command=self.connect_to_network, bg="black", fg="white")
connect_button.pack(pady=5)

disconnect_button = tk.Button(wifi_manager, text="Disconnect",


command=self.disconnect_network, bg="black", fg="white")
disconnect_button.pack(pady=5)

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()

for network in scan_results:


ssid = network.ssid
if ssid not in seen_ssids:
self.networks_listbox.insert(tk.END, ssid)
seen_ssids.add(ssid)

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")

tk.Label(password_window, text="Enter Wi-Fi Password:").pack(pady=10)


password_entry = tk.Entry(password_window, show='*')
password_entry.pack(pady=5)

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")

self.url_entry = ttk.Entry(self, font=("Arial", 14), width=50)


self.url_entry.pack(pady=10)
button_frame = ttk.Frame(self)
button_frame.pack(pady=5)
self.back_button = ttk.Button(button_frame, text="Back",
command=self.go_back)
self.back_button.pack(side=tk.LEFT, padx=5)
self.search_button = ttk.Button(button_frame, text="Search Google",
command=self.google_search)
self.search_button.pack(side=tk.LEFT, padx=5)
self.html_frame = HtmlFrame(self, horizontal_scrollbar="auto")
self.html_frame.pack(fill="both", expand=True)
self.history = []
self.current_page = None

def load_url(self, url):


self.html_frame.load_website(url)
if self.current_page:
self.history.append(self.current_page)
self.current_page = url

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")

text = tk.Text(root, wrap='word')


text.pack(expand=1, fill='both')

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")

track_listbox = tk.Listbox(root, selectmode=tk.SINGLE)


track_listbox.pack(pady=20)

for track in tracks:


track_listbox.insert(tk.END, track)

play_button = tk.Button(root, text="Play", command=lambda:


play_song(track_listbox.get(tk.ACTIVE)))
play_button.pack(side=tk.LEFT, padx=10)

stop_button = tk.Button(root, text="Stop", command=stop_song)


stop_button.pack(side=tk.LEFT, padx=10)

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.snake = [(WIDTH // 2, HEIGHT // 2)]


self.snake_direction = "Right"
self.food = self.spawn_food()
self.running = True

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

head_x, head_y = self.snake[0]


if self.snake_direction == "Up":
head_y -= SNAKE_SIZE
elif self.snake_direction == "Down":
head_y += SNAKE_SIZE
elif self.snake_direction == "Left":
head_x -= SNAKE_SIZE
elif self.snake_direction == "Right":
head_x += SNAKE_SIZE

new_head = (head_x, head_y)


if self.check_collision(new_head):
self.running = False
self.canvas.create_text(WIDTH // 2, HEIGHT // 2, text="Game
Over", fill="white", font=("Arial", 24))
return

self.snake = [new_head] + self.snake[:-1]

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 check_collision(self, head):


if (head[0] < 0 or head[0] >= WIDTH or
head[1] < 0 or head[1] >= HEIGHT or
head in self.snake):
return True
return False

def change_direction(self, event):


if event.keysym in ["Up", "Down", "Left", "Right"]:
if (event.keysym == "Up" and self.snake_direction != "Down" or
event.keysym == "Down" and self.snake_direction != "Up" or
event.keysym == "Left" and self.snake_direction != "Right"
or
event.keysym == "Right" and self.snake_direction !=
"Left"):
self.snake_direction = event.keysym
root = tk.Tk()
game = SimpleSnakeGame(root)
root.mainloop()

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.left_paddle = self.canvas.create_rectangle(20, HEIGHT // 2 -


PADDLE_HEIGHT // 2,
20 + PADDLE_WIDTH,
HEIGHT // 2 + PADDLE_HEIGHT // 2,
fill="white")
self.right_paddle = self.canvas.create_rectangle(WIDTH - 20 -
PADDLE_WIDTH, HEIGHT // 2 - PADDLE_HEIGHT // 2,
WIDTH - 20, HEIGHT
// 2 + PADDLE_HEIGHT // 2,
fill="white")
self.ball = self.canvas.create_oval(WIDTH // 2 - BALL_SIZE // 2,
HEIGHT // 2 - BALL_SIZE // 2,
WIDTH // 2 + BALL_SIZE // 2,
HEIGHT // 2 + BALL_SIZE // 2,
fill="white")

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 on_key_press(self, event):


if event.keysym == "w":
self.left_paddle_up = True
elif event.keysym == "s":
self.left_paddle_down = True
elif event.keysym == "Up":
self.right_paddle_up = True
elif event.keysym == "Down":
self.right_paddle_down = True

def on_key_release(self, event):


if event.keysym == "w":
self.left_paddle_up = False
elif event.keysym == "s":
self.left_paddle_down = False
elif event.keysym == "Up":
self.right_paddle_up = False
elif event.keysym == "Down":
self.right_paddle_down = False

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 ensure_paddle_bounds(self, paddle):


x1, y1, x2, y2 = self.canvas.coords(paddle)
if y1 < 0:
self.canvas.move(paddle, 0, -y1)
if y2 > HEIGHT:
self.canvas.move(paddle, 0, HEIGHT - y2)

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)

if x1 <= 0 or x2 >= WIDTH:


self.ball_speed_x = -self.ball_speed_x
if y1 <= 0 or y2 >= HEIGHT:
self.ball_speed_y = -self.ball_speed_y

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.canvas = tk.Canvas(root, width=640, height=480)


self.canvas.pack()

self.open_button = tk.Button(root, text="Open",


command=self.open_video)
self.open_button.pack(side=tk.LEFT)

self.play_button = tk.Button(root, text="Play",


command=self.play_video)
self.play_button.pack(side=tk.LEFT)

self.stop_button = tk.Button(root, text="Stop",


command=self.stop_video)
self.stop_button.pack(side=tk.LEFT)

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()

You might also like