{"id":17256,"date":"2022-10-23T17:19:51","date_gmt":"2022-10-23T11:49:51","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/"},"modified":"2022-10-23T17:19:51","modified_gmt":"2022-10-23T11:49:51","slug":"solved-tkinter-try-to-keep-using-the-program-on-while-executing","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/","title":{"rendered":"[Solved] Tkinter, try to keep using the program on while executing"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-40646467\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"40646467\" data-parentid=\"40643500\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You can use <code>root.after(miliseconds, function_name, argument)<\/code> to execute function with delay and <code>root.mainloop()<\/code> (and program) will work normally.<\/p>\n<p>You can use <code>datetime<\/code> to convert text to datetime object, substract two dates and get difference in milliseconds.<\/p>\n<pre><code>try:\n    import tkinter as tk\n    import tkinter.messagebox as tkMessageBox\n    print(\"Python 3\")\nexcept:\n    import Tkinter as tk\n    import tkMessageBox\n    print(\"Python 2\")\n\nfrom datetime import datetime as dt\n\n# --- functions ---\n\ndef callback():\n    var_open = open_hour.get()\n    var_close = close_hour.get()\n\n    if not validateDate(var_open, var_close):\n        tkMessageBox.showinfo(\"Error\", \"Incorrect times\")\n    else:\n        # current date and time \n        current = dt.now()\n        print('current:', current)\n\n        # convert strings to `time` object\n        time_open = dt.strptime(var_open, '%H:%M').time()\n        time_close = dt.strptime(var_close, '%H:%M').time()\n\n        print('time_open:', time_open)\n        print('time_close:', time_close)\n\n        # combine `current date` with `time`\n        today_open = dt.combine(current, time_open)\n        today_close = dt.combine(current, time_close)\n\n        print('today_open:', today_open)\n        print('today_close:', today_close)\n\n        # substract dates and get milliseconds\n        milliseconds_open = (today_open - current).seconds * 1000\n        milliseconds_close = (today_close - current).seconds * 1000\n\n        print('milliseconds_open:', milliseconds_open)\n        print('milliseconds_close:', milliseconds_close)\n\n        # run functions with delay\n        root.after(milliseconds_open, show_open_message, var_open)\n        root.after(milliseconds_close, show_close_message, var_close)\n\ndef validateDate(time1, time2):\n    # TODO: check dates\n    return True\n\ndef show_open_message(arg):\n    tkMessageBox.showinfo(\"Info\", \"Open time: \" + arg)\n\ndef show_close_message(arg):\n    tkMessageBox.showinfo(\"Info\", \"Close time: \" + arg)\n\n# --- main ---\n\nroot = tk.Tk()\n\nopen_hour = tk.StringVar()\nclose_hour = tk.StringVar()\n\ne1 = tk.Entry(root, textvariable=open_hour)\ne1.pack()\ne2 = tk.Entry(root, textvariable=close_hour)\ne2.pack()\n\nb = tk.Button(root, text=\"Start\", command=callback)\nb.pack()\n\nroot.mainloop()\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Tkinter, try to keep using the program on while executing <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You can use root.after(miliseconds, function_name, argument) to execute function with delay and root.mainloop() (and program) will work normally. You can use datetime to convert text to datetime object, substract two dates and get difference in milliseconds. try: import tkinter as tk import tkinter.messagebox as tkMessageBox print(&#8220;Python 3&#8221;) except: import Tkinter as tk import tkMessageBox &#8230; <a title=\"[Solved] Tkinter, try to keep using the program on while executing\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\" aria-label=\"More on [Solved] Tkinter, try to keep using the program on while executing\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[349,768],"class_list":["post-17256","post","type-post","status-publish","format-standard","hentry","category-solved","tag-python","tag-tkinter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Tkinter, try to keep using the program on while executing - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Tkinter, try to keep using the program on while executing - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You can use root.after(miliseconds, function_name, argument) to execute function with delay and root.mainloop() (and program) will work normally. You can use datetime to convert text to datetime object, substract two dates and get difference in milliseconds. try: import tkinter as tk import tkinter.messagebox as tkMessageBox print(&quot;Python 3&quot;) except: import Tkinter as tk import tkMessageBox ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-23T11:49:51+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Tkinter, try to keep using the program on while executing\",\"datePublished\":\"2022-10-23T11:49:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\"},\"wordCount\":55,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"python\",\"tkinter\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\",\"name\":\"[Solved] Tkinter, try to keep using the program on while executing - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-23T11:49:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Tkinter, try to keep using the program on while executing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Tkinter, try to keep using the program on while executing - JassWeb","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:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Tkinter, try to keep using the program on while executing - JassWeb","og_description":"[ad_1] You can use root.after(miliseconds, function_name, argument) to execute function with delay and root.mainloop() (and program) will work normally. You can use datetime to convert text to datetime object, substract two dates and get difference in milliseconds. try: import tkinter as tk import tkinter.messagebox as tkMessageBox print(\"Python 3\") except: import Tkinter as tk import tkMessageBox ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/","og_site_name":"JassWeb","article_published_time":"2022-10-23T11:49:51+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Tkinter, try to keep using the program on while executing","datePublished":"2022-10-23T11:49:51+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/"},"wordCount":55,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["python","tkinter"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/","url":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/","name":"[Solved] Tkinter, try to keep using the program on while executing - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-23T11:49:51+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-tkinter-try-to-keep-using-the-program-on-while-executing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Tkinter, try to keep using the program on while executing"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/17256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=17256"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/17256\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=17256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=17256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=17256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}