

{"id":81753,"date":"2020-09-04T09:30:38","date_gmt":"2020-09-04T04:00:38","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=81753"},"modified":"2026-06-01T13:53:12","modified_gmt":"2026-06-01T08:23:12","slug":"python-password-generator","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-password-generator\/","title":{"rendered":"Python Password Generator"},"content":{"rendered":"<p><strong>Learn how to create a random password generator in Python.<\/strong><\/p>\n<p>We know that passwords are a real security threat. To keep your account safe and prevent your password from being hacked you have to make your password hard enough that nobody can guess.<\/p>\n<h3>Password Generator<\/h3>\n<p>It is a tool that generates passwords based on the given guidelines that you set to create an unpredictable strong password for your accounts.<\/p>\n<p>The Password generator tool creates a random and customized password for users that helps them to create a strong password which provides greater security.<\/p>\n<h2>Password Generator Python Project<\/h2>\n<p>&nbsp;<\/p>\n<p>The objective of this project is to create a password generator using python. The password generator project will be build using python modules like Tkinter, random, string, pyperclip.<\/p>\n<p>In this project, the user has to select the password length and then click on the &#8220;<strong>Generate Password<\/strong>&#8221; button. It will show the generated password below. If the user clicks on the &#8220;<strong>Copy To Clipboard<\/strong>&#8221; button, then it will copy the password automatically.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>To build this project we will use the basic concept of python and libraries &#8211; Tkinter, pyperclip, random, string.<\/p>\n<ul>\n<li><strong>Tkinter<\/strong> is a standard GUI library and is one of the easiest ways to build a GUI application.<\/li>\n<li><strong>pyperclip<\/strong> module allows us to copy and paste text to and from the clipboard to your computer<\/li>\n<li><strong>The random<\/strong> module can generate random numbers<\/li>\n<li><strong>string<\/strong> module contains a number of functions to process the standard python string.<\/li>\n<\/ul>\n<p>To install the libraries we can use pip installer from the command line:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pip install tkinter\r\npip install pyperclip\r\npip install random\r\npip install strings\r\n<\/pre>\n<h3>Download Project Code<\/h3>\n<p>Download the source code of the password generator project: <a href=\"https:\/\/drive.google.com\/file\/d\/1S9wvh6xU9LZH1dVxq2FFWYc9jmKVnsfy\/view?usp=drive_link\"><strong>Python Password Generator<\/strong><\/a><\/p>\n<h3>Project File Structure<\/h3>\n<p>Let\u2019s check the step to build a Password Generator using Python<\/p>\n<ul>\n<li>Import modules<\/li>\n<li>Initialized Window<\/li>\n<li>Select Password Length<\/li>\n<li>Define Functions<\/li>\n<\/ul>\n<h3>Steps to create random password generator<\/h3>\n<h4>1. Import Libraries<\/h4>\n<p>The first step is to import libraries<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from tkinter import *\r\nimport random, string\r\nimport pyperclip\r\n<\/pre>\n<h4>2. Initialize Window<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">root = Tk()\r\nroot.geometry(\"400x400\")\r\nroot.resizable(0,0)\r\nroot.title(\"DataFlair - PASSWORD GENERATOR\")\r\n<\/pre>\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>title()<\/strong> set the title of the window<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Label(root, text = 'PASSWORD GENERATOR' , font ='arial 15 bold').pack()\r\nLabel(root, text ='DataFlair', font ='arial 15 bold').pack(side = BOTTOM)\r\n<\/pre>\n<p><strong>Label()<\/strong> widget use to display one or more than one line of text that users can\u2019t able to modify.<\/p>\n<ul>\n<li><strong>root<\/strong> is the name which we refer to our window<\/li>\n<li><strong>text<\/strong> which we display on the label<\/li>\n<li><strong>font<\/strong> in which the text is written<\/li>\n<li><strong>pack<\/strong> organized widget in block<\/li>\n<\/ul>\n<h4>3. Select Password Length<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pass_label = Label(root, text = 'PASSWORD LENGTH', font = 'arial 10 bold').pack()\r\npass_len = IntVar()\r\nlength = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack()\r\n<\/pre>\n<ul>\n<li><strong>pass_len<\/strong> is an integer type variable that stores the length of a password.<\/li>\n<li>To select the password length we use <strong>Spinbox()<\/strong> widget.<\/li>\n<li><strong>Spinbox()<\/strong> widget is used to select from a fixed number of values. Here the value from 8 to 32<\/li>\n<\/ul>\n<h4>4. Function to Generate Password<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pass_str = StringVar()\r\ndef Generator():\r\n    password = ''\r\n\r\n    for x in range (0,4):\r\n        password = random.choice(string.ascii_uppercase) + random.choice(string.ascii_lowercase) + random.choice(string.digits) + random.choice(string.punctuation)\r\n    for y in range(pass_len.get()- 4):\r\n        password = password + random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation)\r\n    pass_str.set(password)\r\n<\/pre>\n<ul>\n<li><strong>pass_str<\/strong> is a string type variable that stores the generated password<\/li>\n<li><strong>password<\/strong> = &#8220;&#8221; is the empty string<\/li>\n<li>First loop will generate a string of length 4 which is a combination of an uppercase letter, a lowercase letter, digits, and a special symbol and that string will store in password variable.<\/li>\n<li>The second loop will generate a random string of length entered by the user &#8211; 4 and add to the password variable. Here we minus 4 to the length of the user because we already generate the string of length 4.<\/li>\n<\/ul>\n<p>We have done this because we want a password which must contain an uppercase, a lowercase, a digit, and a special symbol.<\/p>\n<p>Now the password is set to the <strong>pass_str()<\/strong> variable.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Button(root, text = \"GENERATE PASSWORD\" , command = Generator ).pack(pady= 5)\r\n\r\nEntry(root , textvariable = pass_str).pack()\r\n<\/pre>\n<ul>\n<li><strong>Button()<\/strong> widget used to display button on our window<\/li>\n<li><strong>command<\/strong> is called when the button is click<\/li>\n<li><strong>Entry()<\/strong> widget used to create an input text field<\/li>\n<li><strong>textvariable<\/strong> used to retrieve the current text to the entry widget<\/li>\n<\/ul>\n<h4>5. Function to Copy Password<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def Copy_password():\r\n    pyperclip.copy(pass_str.get())\r\n\r\nButton(root, text = 'COPY TO CLIPBOARD', command = Copy_password).pack(pady=5)\r\n\r\n<\/pre>\n<p><strong>pyperclip.copy()<\/strong> used to copy the text to clipboard<\/p>\n<h3>Python Password Generator Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81758\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output.png\" alt=\"random password generator output\" width=\"580\" height=\"625\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output.png 580w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output-278x300.png 278w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output-139x150.png 139w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/random-password-generator-output-520x560.png 520w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>With these steps, we have successfully created a random password generator project using python. We used popular tkinter library to rendering graphics in our display window and we also learned about pyperclip and random library.<\/p>\n<p>We learned how to create buttons, input textfield, labels, and spinbox. In this way, we successfully created our password generator python project. Hope you enjoyed it.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2578,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1S9wvh6xU9LZH1dVxq2FFWYc9jmKVnsfy\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601082314\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1S9wvh6xU9LZH1dVxq2FFWYc9jmKVnsfy\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 10:21:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-04 23:35:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-09 00:03:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-12 05:29:15&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-12 05:29:15&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create a random password generator in Python. We know that passwords are a real security threat. To keep your account safe and prevent your password from being hacked you have to&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":81757,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[23191,21082,22734,23192],"class_list":["post-81753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-password-generator","tag-python-project","tag-python-project-for-beginners","tag-random-password-generator"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Password Generator - DataFlair<\/title>\n<meta name=\"description\" content=\"Python password generator - Random password generator project will be build using python modules like Tkinter, random, string, pyperclip.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-password-generator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Password Generator - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python password generator - Random password generator project will be build using python modules like Tkinter, random, string, pyperclip.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-password-generator\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-04T04:00:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T08:23:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.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=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Password Generator - DataFlair","description":"Python password generator - Random password generator project will be build using python modules like Tkinter, random, string, pyperclip.","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:\/\/data-flair.training\/blogs\/python-password-generator\/","og_locale":"en_US","og_type":"article","og_title":"Python Password Generator - DataFlair","og_description":"Python password generator - Random password generator project will be build using python modules like Tkinter, random, string, pyperclip.","og_url":"https:\/\/data-flair.training\/blogs\/python-password-generator\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-09-04T04:00:38+00:00","article_modified_time":"2026-06-01T08:23:12+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"Python Password Generator","datePublished":"2020-09-04T04:00:38+00:00","dateModified":"2026-06-01T08:23:12+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/"},"wordCount":680,"commentCount":20,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.jpg","keywords":["python password generator","Python project","python project for beginners","random password generator"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-password-generator\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/","url":"https:\/\/data-flair.training\/blogs\/python-password-generator\/","name":"Python Password Generator - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.jpg","datePublished":"2020-09-04T04:00:38+00:00","dateModified":"2026-06-01T08:23:12+00:00","description":"Python password generator - Random password generator project will be build using python modules like Tkinter, random, string, pyperclip.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-password-generator\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/python-password-generator.jpg","width":1200,"height":628,"caption":"python password generator"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-password-generator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Password Generator"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=81753"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81753\/revisions"}],"predecessor-version":[{"id":148660,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81753\/revisions\/148660"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81757"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=81753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=81753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=81753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}