This project requires a basic understanding of Python, including concepts like defining functions and using loops. To use the Tkinter module, you need to install it using the following command:
pip install tk
Let's take a look at the steps involved in creating the Python Website Blocker project:
- Importing the Required Library:
We only require the Tkinter module to create the GUI in Python.
from tkinter import *
- Creating GUI Window:
window = Tk()
window.geometry('650x400')
window.minsize(650,400)
window.maxsize(650,400)
window.title("Website Blocker")
heading=Label(window, text ='Website Blocker' , font ='arial')
heading.pack()
- Host Path and IP Address:
host_path ='C:\Windows\System32\drivers\etc\hosts'
ip_address = '127.0.0.1'
- Create Block Function:
def Blocker():
# Function code here
- Unblock Function:
def Unblock():
# Function code here
- Creating Labels and Buttons:
label1=Label(window, text ='Enter Website :' , font ='arial 13 bold')
label1.place(x=5 ,y=60)
enter_Website = Text(window,font = 'arial',height='2', width = '40')
enter_Website.place(x= 140,y = 60)
- Main Command:
window.mainloop()
While working with the host file, you need to run the code as an administrator in the command prompt to make changes to the host file. Attempting to run the file directly may result in a "Permission not granted" error.
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.