-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-website-blocker-GUI.py
41 lines (33 loc) · 1.42 KB
/
python-website-blocker-GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#import library
from tkinter import *
#initialize window
root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("Nihal Mohammed - Website Blocker")
#heading
Label(root, text = 'WEBSITE BLOCKER' , font = 'arial 20 bold').pack()
Label(root,text = 'Proudly Presented By Nihal Mohammed' , font = 'arial 20 bold').pack(side = BOTTOM)
#path of our host file ang ip address
host_path = 'C:\Windows\System32\drivers\etc\hosts'
ip_address = '127.0.0.1'
#ENTER WEBSITE
Label(root, text= 'Enter Website :', font = 'arial 13 bold').place(x=5,y=60)
Websites = Text(root, font = 'arial 10', height ='2', width = '40', wrap = WORD,padx = 5, pady=5)
Websites.place(x = 140, y =60)
#block function
def Blocker():
website_lists = Websites.get(1.0,END)
Website = list(website_lists.split(","))
with open (host_path , 'r+') as host_file:
file_content = host_file.read()
for website in Website:
if website in file_content:
Label(root, text = 'Already Blocked' , font = 'arial 12 bold').place(x=200,y=200)
pass
else:
host_file.write(ip_address + " " + website + '\n')
Label(root, text = "Blocked", font = 'arial 12 bold').place(x=230,y =200)
block_btn = Button(root, text = 'BLOCK' , font = 'arial 12 bold', command = Blocker, width = 6 , bg = 'royal blue1', activebackground = 'sky blue')
block_btn.place(x = 230, y =150)
root.mainloop