Hi, this is my code to build a fully GUI enabled menu to do various tasks/functions. This is completely customizable and we can adjust it to our needs.

Drishan T Gupta
3 min readAug 1, 2023

--

You can install all of the used libraries using pip install <libraryname> and i have explained what each of the blocks do in comments denoted by #

import os
import pywhatkit as pwk
from datetime import datetime
import smtplib, ssl
import requests
import YouTubeMusicAPI
import tkinter as tk
from tkinter import ttk

def open_notepad(): #we define a function open_notepad which will
#open notepad through os.system
os.system("notepad")

def open_browser(): #similarly this one opens msedge through os.system
os.system("start msedge")

def open_facebook(): #if we are opening a browser, we can pass a link
os.system("start msedge www.facebook.com")#to some website as an argument

def open_gmail():
os.system("start msedge www.gmail.com")

def open_whatsapp():
os.system("start msedge https://web.whatsapp.com/")

def open_youtube():
os.system("start msedge www.youtube.com")

def open_reddit():
os.system("start msedge www.reddit.com")

def open_linuxworld():
os.system("start msedge https://www.lwindia.com/")

def send_whatsapp_message(): #through pywhatkit we will be sending text messages to some number
time = datetime.now()
timeh = int(time.strftime("%H"))
timem = int(time.strftime("%M"))
uptimem = timem + 1

number = number_entry.get()
message = message_entry.get()

if message and number:
pwk.sendwhatmsg("+91" + number, message, timeh, uptimem)
else:
print("Please enter both the message and the number.")
message_entry.delete(0, tk.END)
number_entry.delete(0, tk.END)

def play_song():
song_name = song_entry.get()
query = song_name

result = YouTubeMusicAPI.search(query)#we can simply play a youtube music video
#if we pass a song link as argument
if result:
os.system("start msedge " + result["url"])
else:
print("No Result Found")

def search_video():
video_name = video_entry.get()
video_name = video_name.replace(" ", "+")

if video_name:
os.system("start msedge https://www.youtube.com/results?search_query=" + video_name)
else:
print("No Result Found")

def send_email():
receiver_email = email_entry.get()
password = "generated key here"
message_email = email_message_entry.get()

if receiver_email and message_email:
port = 465
smtp_server = "smtp.gmail.com"
sender_email = "sender@gmail.com"

context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message_email)
else:
print("Please enter both the receiver email and the message.")

email_entry.delete(0, tk.END)
email_message_entry.delete(0, tk.END)

# Create the main window
root = tk.Tk()
root.title("Commands Through Buttons")
root.geometry("800x800") # Set the initial size of the window

# Create a title label
title_label = tk.Label(root, text="Commands Through Buttons", font=("calibri", 20, "bold"), bg="#dfe6e9", fg="#2d3436")
title_label.pack(fill=tk.X, padx=10, pady=10)

# Create buttons for each specific command and functionality
style = ttk.Style()
style.configure('TButton', font=('calibri', 12, 'bold'), foreground='#2d3436', background='#dfe6e9')

notepad_button = ttk.Button(root, text="Open Notepad", command=open_notepad)
notepad_button.pack(fill=tk.X, padx=20, pady=5)

browser_button = ttk.Button(root, text="Open Browser", command=open_browser)
browser_button.pack(fill=tk.X, padx=20, pady=5)

facebook_button = ttk.Button(root, text="Open Facebook", command=open_facebook)
facebook_button.pack(fill=tk.X, padx=20, pady=5)

gmail_button = ttk.Button(root, text="Open Gmail", command=open_gmail)
gmail_button.pack(fill=tk.X, padx=20, pady=5)

whatsapp_button = ttk.Button(root, text="Open WhatsApp", command=open_whatsapp)
whatsapp_button.pack(fill=tk.X, padx=20, pady=5)

youtube_button = ttk.Button(root, text="Open YouTube", command=open_youtube)
youtube_button.pack(fill=tk.X, padx=20, pady=5)

reddit_button = ttk.Button(root, text="Open Reddit", command=open_reddit)
reddit_button.pack(fill=tk.X, padx=20, pady=5)

linuxworld_button = ttk.Button(root, text="Open LinuxWorld", command=open_linuxworld)
linuxworld_button.pack(fill=tk.X, padx=20, pady=5)

# Create entry fields and buttons for additional functionalities
message_entry = ttk.Entry(root)
message_entry.pack(fill=tk.X, padx=20, pady=5)

number_entry = ttk.Entry(root)
number_entry.pack(fill=tk.X, padx=20, pady=5)

send_whatsapp_button = ttk.Button(root, text="Send WhatsApp Message", command=send_whatsapp_message)
send_whatsapp_button.pack(fill=tk.X, padx=20, pady=5)

song_entry = ttk.Entry(root)
song_entry.pack(fill=tk.X, padx=20, pady=5)

play_song_button = ttk.Button(root, text="Play Song", command=play_song)
play_song_button.pack(fill=tk.X, padx=20, pady=5)

video_entry = ttk.Entry(root)
video_entry.pack(fill=tk.X, padx=20, pady=5)

search_video_button = ttk.Button(root, text="Search Video", command=search_video)
search_video_button.pack(fill=tk.X, padx=20, pady=5)

email_entry = ttk.Entry(root)
email_entry.pack(fill=tk.X, padx=20, pady=5)

email_message_entry = ttk.Entry(root)
email_message_entry.pack(fill=tk.X, padx=20, pady=5)

send_email_button = ttk.Button(root, text="Send Email", command=send_email)
send_email_button.pack(fill=tk.X, padx=20, pady=5)

# Run the main event loop
root.mainloop()
#here we created buttons for each of the functions
This is how our code and output looks like

--

--

Drishan T Gupta
Drishan T Gupta

No responses yet