{"id":79781,"date":"2020-09-08T09:30:14","date_gmt":"2020-09-08T04:00:14","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79781"},"modified":"2026-06-03T15:51:04","modified_gmt":"2026-06-03T10:21:04","slug":"python-website-blocker","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/","title":{"rendered":"Python Website Blocker with GUI"},"content":{"rendered":"<p><strong>Create a Website Blocker in Python<\/strong> &#8211; Block any Unwanted Website<\/p>\n<p>Website Blocker is a tool that denies access to websites permanently or by schedule. To use the internet safely we can block all websites from unwanted categories.<\/p>\n<h3>Website Blocker Python Project<\/h3>\n<p>The objective of Website Blocker python project is to block the given websites from any device. This project will help the user to stay away from their distraction by blocking websites from their device so that they can not open them.<\/p>\n<p>In this Python Website Blocker Project, the user can enter multiple websites to block, and then clicking on the block button will check the condition that if the website already blocked then print \u2018already blocked\u2019 else blocked all that websites and print \u2018blocked\u2019.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>To implement website blocker project, we will use the basic concepts of Python and Tkinter library.<\/p>\n<p><strong>Tkinter<\/strong> is a standard GUI Python library. It is one of the fastest and easiest ways to build GUI applications using Tkinter.<\/p>\n<p>To install the library, you can use pip install command to the command prompt:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pip install tkinter\r\n<\/pre>\n<h3>Download Website Blocker Project code<\/h3>\n<p>Please download the source code of website blocker project: <a href=\"https:\/\/drive.google.com\/file\/d\/1vVEn9un1QYNv5bMhL7bpj1GDWdB0tGCw\/view?usp=drive_link\"><strong>Python Website Blocker<\/strong><\/a><\/p>\n<h3>Steps to build Website blocker Python Project:<\/h3>\n<ul>\n<li>Importing the module<\/li>\n<li>Create the display window<\/li>\n<li>Create an entry widget<\/li>\n<li>Define function<\/li>\n<li>Create a block button<\/li>\n<\/ul>\n<h4>1. Importing the module<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from tkinter import *\r\n<\/pre>\n<p>We import modules from tkinter library<\/p>\n<h4>2. Create the display window<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">root = Tk()\r\nroot.geometry('500x300')\r\nroot.resizable(0,0)\r\nroot.title(\"TechVidvan - Website Blocker\")\r\n<\/pre>\n<p>We use tkinter library to create a window where we\u2019ll enter our text which we want to convert into voice.<\/p>\n<ul>\n<li><strong>Tk()<\/strong> initialized tkinter which means window created<\/li>\n<li><strong>geometry()<\/strong> set the width and height of the window<\/li>\n<li><strong>resizable(0,0)<\/strong> set the fixed size of the window<\/li>\n<li><strong>bg = \u2018\u2019<\/strong> use to set the background color<\/li>\n<li><strong>title()<\/strong> used to set the title of the window<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Label(root, text ='WEBSITE BLOCKER' , font ='arial 20 bold').pack()\r\nLabel(root, text ='TechVidvan' , font ='arial 20 bold').pack(side=BOTTOM)\r\n<\/pre>\n<p><strong>Label()<\/strong> widget is used to display one or more than one line of text that users aren&#8217;t able to modify.<\/p>\n<ul>\n<li><strong>root<\/strong> &#8211; name which we refer to our window<\/li>\n<li><strong>text<\/strong> &#8211; which we display on the label<\/li>\n<li><strong>font<\/strong> &#8211; in which the text is written<\/li>\n<li><strong>pack<\/strong> &#8211; organized widget in block<\/li>\n<\/ul>\n<h4>3. Create an entry widget<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">host_path ='C:\\Windows\\System32\\drivers\\etc\\hosts'\r\nip_address = '127.0.0.1'\r\n\r\nLabel(root, text ='Enter Website :' , font ='arial 13 bold').place(x=5 ,y=60)\r\nWebsites = Text(root,font = 'arial 10',height='2', width = '40', wrap = WORD, padx=5, pady=5)\r\nWebsites.place(x= 140,y = 60)\r\n<\/pre>\n<ul>\n<li><strong>host_path<\/strong> stores the path of our host file<\/li>\n<li><strong>ip_address<\/strong> stores the IP address used by localhost<\/li>\n<li><strong>Text()<\/strong> widget is used for multi-line text areas.<\/li>\n<li><strong>wrap = WORD<\/strong> will break the line after the last word.<\/li>\n<li><strong>padx<\/strong> puts an extra bit space on left and right side of the widget<\/li>\n<li><strong>pady<\/strong> puts extra space on top and bottom side of the widget.<\/li>\n<\/ul>\n<p>4. Define function<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def Blocker():\r\n    website_lists = Websites.get(1.0,END)\r\n    Website = list(website_lists.split(\",\"))\r\n\r\n    with open (host_path , 'r+') as host_file:\r\n        file_content = host_file.read()\r\n        for website in Website:\r\n            if website in file_content:\r\n                Label(root, text = 'Already Blocked' , font = 'arial 12 bold').place(x=200,y=200)\r\n                pass\r\n            else:\r\n                host_file.write(ip_address + \" \" + website + '\\n')\r\n                Label(root, text = \"Blocked\", font = 'arial 12 bold').place(x=230,y =200)\r\n<\/pre>\n<ul>\n<li><strong>website_lists<\/strong> get all the Websites to enter by the users<\/li>\n<li><strong>website_list(lists.split(&#8220;,&#8221;))<\/strong> split the content of the lists by comma and then convert it into list ad store it into Website<\/li>\n<li><strong>with open<\/strong> &#8211; The with open statement open the file and it will automatically close the file handler when we are done with it<\/li>\n<li><strong>r+<\/strong> will use to open a file for reading and writing<\/li>\n<li><strong>If<\/strong> the website is already in file_content then print a label with text already blocked.<\/li>\n<li><strong>Else<\/strong> it will block all the given website and print label of text \u2018Blocked\u2019.<\/li>\n<\/ul>\n<p>5. Create a block button<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">block = Button(root, text = 'Block',font = 'arial 12 bold',pady = 5,command = Blocker ,width = 6, bg = 'royal blue1', activebackground = 'sky blue')\r\n\r\nblock.place(x = 230, y = 150)\r\nroot.mainloop()\r\n<\/pre>\n<p>When we click on the Block button it will call the Blocker function.<\/p>\n<ul>\n<li><strong>Button()<\/strong> &#8211; used to display button on our window<\/li>\n<li><strong>command<\/strong> &#8211; called when we click the button.<\/li>\n<li><strong>activebackground<\/strong> &#8211; sets the background color to use when the button is click<\/li>\n<\/ul>\n<h3>Website Blocker Project Output<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/09\/website-blocker-project-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79784\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/09\/website-blocker-project-output.png\" alt=\"website blocker project output\" width=\"1366\" height=\"727\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>We have successfully developed the Website Blocker python project. We used the popular Tkinter library for rendering graphics on a display window and the basic concept of python programming.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a Website Blocker in Python &#8211; Block any Unwanted Website Website Blocker is a tool that denies access to websites permanently or by schedule. To use the internet safely we can block all&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79785,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[483,3249,3250],"class_list":["post-79781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-project","tag-python-project-for-beginners","tag-python-website-blocker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Website Blocker with GUI - TechVidvan<\/title>\n<meta name=\"description\" content=\"Python Website Blocker - Create a website blocker python project with basic concepts of python and tkinter. This project blocks unwanted websites and help you in safe browsing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Website Blocker with GUI - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Python Website Blocker - Create a website blocker python project with basic concepts of python and tkinter. This project blocks unwanted websites and help you in safe browsing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-08T04:00:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T10:21:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Website Blocker with GUI - TechVidvan","description":"Python Website Blocker - Create a website blocker python project with basic concepts of python and tkinter. This project blocks unwanted websites and help you in safe browsing.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/","og_locale":"en_US","og_type":"article","og_title":"Python Website Blocker with GUI - TechVidvan","og_description":"Python Website Blocker - Create a website blocker python project with basic concepts of python and tkinter. This project blocks unwanted websites and help you in safe browsing.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-09-08T04:00:14+00:00","article_modified_time":"2026-06-03T10:21:04+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Python Website Blocker with GUI","datePublished":"2020-09-08T04:00:14+00:00","dateModified":"2026-06-03T10:21:04+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/"},"wordCount":600,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg","keywords":["Python project","python project for beginners","python website blocker"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/","url":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/","name":"Python Website Blocker with GUI - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg","datePublished":"2020-09-08T04:00:14+00:00","dateModified":"2026-06-03T10:21:04+00:00","description":"Python Website Blocker - Create a website blocker python project with basic concepts of python and tkinter. This project blocks unwanted websites and help you in safe browsing.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/python-website-blocker.jpg","width":1200,"height":628,"caption":"python website blocker"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-website-blocker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python Website Blocker with GUI"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":false,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79781"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79781\/revisions"}],"predecessor-version":[{"id":448141,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79781\/revisions\/448141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79785"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}