-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-website-blocker.py
More file actions
41 lines (33 loc) · 1.46 KB
/
python-website-blocker.py
File metadata and controls
41 lines (33 loc) · 1.46 KB
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("Vaibhav - Website Blocker")
#Heading
Label(root, text = 'WEBSITE BLOCKER' , font = 'arial 20 bold').pack()
Label(root,text = 'Vaibhav' , font = 'arial 20 bold').pack(side = BOTTOM)
#Path of our host file and ip address
host_path = ' '#stores the path of our host file
ip_address = ' '#stores the IP address used by localhost
#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