{"id":453,"date":"2023-02-16T07:39:32","date_gmt":"2023-02-16T07:39:32","guid":{"rendered":"https:\/\/tinyytopic.com\/?p=453"},"modified":"2023-02-16T07:38:50","modified_gmt":"2023-02-16T07:38:50","slug":"a-progress-bar-with-status-in-percentage","status":"publish","type":"post","link":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/","title":{"rendered":"A Progress bar with status in percentage"},"content":{"rendered":"\n<div class=\"wp-block-uagb-advanced-heading uagb-block-84c700ee\"><h5 class=\"uagb-heading-text\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><br>How to create a Progress bar with a status display in percentage?<\/mark><\/h5><\/div>\n\n\n\n<p style=\"font-size:15px\">Install the following module(s) if you haven&#8217;t installed them already:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install tkinter<\/code><\/pre>\n\n\n\n<p style=\"font-size:15px\">Ready-to-use Python function to display the progress bar along with the status text in percentage:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def progress_bar_with_status(master, x_loc, y_loc, bar_length, total_lines):\n    global CurrentLine\n\n    # check if variable is defined\n    try: CurrentLine\n    except: CurrentLine = 0\n    \n    # Remove if label exists\n    try:\n        txtProgress.config(text='')\n    except:\n        txtProgress = Label(master, text = '0%', bg = '#345', fg = '#fff')\n    txtProgress = Label(master, text = '0%', bg = '#345', fg = '#fff') #Progress Label\n    \n    # progress bar with status\n    CurrentLine +=1\n    progress = ttk.Progressbar(master, orient = HORIZONTAL, length = bar_length, mode = 'determinate')\n    progress.pack(pady = 10)\n    progress.place(x=x_loc, y = y_loc)\n    progress['value'] = math.floor(CurrentLine * 100\/total_lines)\n    txtProgress.place(x=bar_length+30, y = y_loc)\n    txtProgress['text'] = progress['value'],'%'\n    master.update()<\/pre>\n\n\n\n<p style=\"font-size:15px\">Write your main code as a sample below,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root = Tk()\r\nroot.title(\"Progress\")\r\nroot.geometry(\"605x550\")\r\ntotal_lines = 5\r\nfor i in range(0, total_lines):\r\n    time.sleep(1)\r\n    progress_bar_with_status(root, 20, 30, 150, total_lines)\r\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p style=\"font-size:15px\">The output of the code is,<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tinyytopic.com\/wp-content\/uploads\/2023\/02\/progress-bar.gif\" alt=\"\" class=\"wp-image-454\" width=\"607\" height=\"115\"\/><\/figure>\n\n\n\n<div class=\"wp-block-uagb-advanced-heading uagb-block-1a07a469\"><h5 class=\"uagb-heading-text\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><br>How does the function work?<\/mark><\/h5><\/div>\n\n\n\n<p style=\"font-size:15px\">This is a Python function that creates a progress bar with a status label in a graphical user interface (GUI) using the <strong>tkinter <\/strong>and <strong>ttk <\/strong>libraries.<\/p>\n\n\n\n<p style=\"font-size:15px\">Here&#8217;s how the function works:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The function takes five arguments:\n<ul class=\"wp-block-list\">\n<li><code>master<\/code>: the parent window or frame of the progress bar<\/li>\n\n\n\n<li><code>x_loc<\/code>: the x-coordinate of the top-left corner of the progress bar<\/li>\n\n\n\n<li><code>y_loc<\/code>: the y-coordinate of the top-left corner of the progress bar<\/li>\n\n\n\n<li><code>bar_length<\/code>: the length of the progress bar in pixels<\/li>\n\n\n\n<li><code>total_lines<\/code>: the total number of lines to be processed, which is used to calculate the progress percentage<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>The <code>global<\/code> keyword is used to declare the <code>CurrentLine<\/code> variable as a global variable so that it can be used and modified within the function.<\/li>\n\n\n\n<li>The function checks if the <code>CurrentLine<\/code> variable is defined. If it is not defined, it is set to zero.<\/li>\n\n\n\n<li>The function tries to remove the progress label if it already exists, and creates a new one with the initial text &#8220;0%&#8221;.<\/li>\n\n\n\n<li>The function creates a <code>ttk.Progressbar<\/code> widget with a horizontal orientation, a specified length, and a &#8220;determinate&#8221; mode, which means the progress bar fills up gradually as progress is made.<\/li>\n\n\n\n<li>The <code>place<\/code> method is used to position the progress bar at the specified <code>x_loc<\/code> and <code>y_loc<\/code> coordinates.<\/li>\n\n\n\n<li>The progress percentage is calculated by dividing the current line number by the total number of lines, multiplying by 100, and rounding down to the nearest integer using the <code>math.floor<\/code> function.<\/li>\n\n\n\n<li>The progress label is positioned to the right of the progress bar.<\/li>\n\n\n\n<li>The progress label text is updated to display the progress percentage followed by a &#8220;%&#8221; symbol.<\/li>\n\n\n\n<li>The <code>master.update()<\/code> method is called to update the GUI with the progress bar and label.<\/li>\n\n\n\n<li>The progress value of the progress bar is set to the progress percentage.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Install the following module(s) if you haven&#8217;t installed them already: Ready-to-use Python function to display the progress bar along with the status text in percentage: Write your main code as a sample below, The output of the code is, This is a Python function that creates a progress bar with a status label in a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12,17],"tags":[14,28,13,16,15,29],"class_list":["post-453","post","type-post","status-publish","format-standard","hentry","category-python","category-useful-function","tag-programming-language","tag-progress-bar","tag-python","tag-python-code","tag-python-sample-code","tag-status"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Progress bar with status in percentage - tinyytopic.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Progress bar with status in percentage - tinyytopic.com\" \/>\n<meta property=\"og:description\" content=\"Install the following module(s) if you haven&#8217;t installed them already: Ready-to-use Python function to display the progress bar along with the status text in percentage: Write your main code as a sample below, The output of the code is, This is a Python function that creates a progress bar with a status label in a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/\" \/>\n<meta property=\"og:site_name\" content=\"tinyytopic.com\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-16T07:39:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-16T07:38:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tinyytopic.com\/wp-content\/uploads\/2023\/02\/progress-bar.gif\" \/>\n<meta name=\"author\" content=\"tinyytopic.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"tinyytopic.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/\",\"url\":\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/\",\"name\":\"A Progress bar with status in percentage - tinyytopic.com\",\"isPartOf\":{\"@id\":\"https:\/\/tinyytopic.com\/#website\"},\"datePublished\":\"2023-02-16T07:39:32+00:00\",\"dateModified\":\"2023-02-16T07:38:50+00:00\",\"author\":{\"@id\":\"https:\/\/tinyytopic.com\/#\/schema\/person\/56c840cea8539fb221a03c5fa2ef32eb\"},\"breadcrumb\":{\"@id\":\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tinyytopic.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Progress bar with status in percentage\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tinyytopic.com\/#website\",\"url\":\"https:\/\/tinyytopic.com\/\",\"name\":\"tinyytopic.com\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tinyytopic.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tinyytopic.com\/#\/schema\/person\/56c840cea8539fb221a03c5fa2ef32eb\",\"name\":\"tinyytopic.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tinyytopic.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5f153681c8ca1e6d7287d858de51f968bb687221c89cf96d763ead4393881029?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5f153681c8ca1e6d7287d858de51f968bb687221c89cf96d763ead4393881029?s=96&d=mm&r=g\",\"caption\":\"tinyytopic.com\"},\"sameAs\":[\"http:\/\/tinyytopic.com\"],\"url\":\"https:\/\/tinyytopic.com\/index.php\/author\/mmkmuthukumar21gmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Progress bar with status in percentage - tinyytopic.com","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:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/","og_locale":"en_US","og_type":"article","og_title":"A Progress bar with status in percentage - tinyytopic.com","og_description":"Install the following module(s) if you haven&#8217;t installed them already: Ready-to-use Python function to display the progress bar along with the status text in percentage: Write your main code as a sample below, The output of the code is, This is a Python function that creates a progress bar with a status label in a [&hellip;]","og_url":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/","og_site_name":"tinyytopic.com","article_published_time":"2023-02-16T07:39:32+00:00","article_modified_time":"2023-02-16T07:38:50+00:00","og_image":[{"url":"https:\/\/tinyytopic.com\/wp-content\/uploads\/2023\/02\/progress-bar.gif"}],"author":"tinyytopic.com","twitter_card":"summary_large_image","twitter_misc":{"Written by":"tinyytopic.com","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/","url":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/","name":"A Progress bar with status in percentage - tinyytopic.com","isPartOf":{"@id":"https:\/\/tinyytopic.com\/#website"},"datePublished":"2023-02-16T07:39:32+00:00","dateModified":"2023-02-16T07:38:50+00:00","author":{"@id":"https:\/\/tinyytopic.com\/#\/schema\/person\/56c840cea8539fb221a03c5fa2ef32eb"},"breadcrumb":{"@id":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/tinyytopic.com\/index.php\/2023\/02\/16\/a-progress-bar-with-status-in-percentage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tinyytopic.com\/"},{"@type":"ListItem","position":2,"name":"A Progress bar with status in percentage"}]},{"@type":"WebSite","@id":"https:\/\/tinyytopic.com\/#website","url":"https:\/\/tinyytopic.com\/","name":"tinyytopic.com","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tinyytopic.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tinyytopic.com\/#\/schema\/person\/56c840cea8539fb221a03c5fa2ef32eb","name":"tinyytopic.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tinyytopic.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5f153681c8ca1e6d7287d858de51f968bb687221c89cf96d763ead4393881029?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5f153681c8ca1e6d7287d858de51f968bb687221c89cf96d763ead4393881029?s=96&d=mm&r=g","caption":"tinyytopic.com"},"sameAs":["http:\/\/tinyytopic.com"],"url":"https:\/\/tinyytopic.com\/index.php\/author\/mmkmuthukumar21gmail-com\/"}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"tinyytopic.com","author_link":"https:\/\/tinyytopic.com\/index.php\/author\/mmkmuthukumar21gmail-com\/"},"uagb_comment_info":83,"uagb_excerpt":"Install the following module(s) if you haven&#8217;t installed them already: Ready-to-use Python function to display the progress bar along with the status text in percentage: Write your main code as a sample below, The output of the code is, This is a Python function that creates a progress bar with a status label in a&hellip;","_links":{"self":[{"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/posts\/453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":11,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions\/465"}],"wp:attachment":[{"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tinyytopic.com\/index.php\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}