{"id":770,"date":"2019-09-07T23:16:39","date_gmt":"2019-09-07T14:16:39","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=770"},"modified":"2022-01-08T01:03:33","modified_gmt":"2022-01-07T16:03:33","slug":"%e3%80%90python%e3%80%91tkinter%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e4%b8%80%e5%ae%9a%e6%99%82%e9%96%93%e3%81%94%e3%81%a8%e3%81%ab%e8%87%aa%e5%8b%95%e5%88%87%e6%8f%9b%e3%81%88","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=770","title":{"rendered":"\u3010Python\u3011tkinter\u3067\u753b\u50cf\u3092\u4e00\u5b9a\u6642\u9593\u3054\u3068\u306b\u81ea\u52d5\u5207\u63db\u3048"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/obenkyolab.com\/?p=770\/#%E7%9B%AE%E7%9A%84\" >\u76ee\u7684<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=770\/#%E4%BD%BF%E7%94%A8%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA\" >\u4f7f\u7528\u30e9\u30a4\u30d6\u30e9\u30ea<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/obenkyolab.com\/?p=770\/#Step1_%E3%81%AB%E3%82%88%E3%82%8B%E7%94%BB%E5%83%8F%E8%A1%A8%E7%A4%BA\" >Step1 : \u306b\u3088\u308b\u753b\u50cf\u8868\u793a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/obenkyolab.com\/?p=770\/#Step2_%E7%94%BB%E5%83%8F%E3%81%AE%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88\" >Step2 : \u753b\u50cf\u306e\u5207\u308a\u66ff\u3048<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/obenkyolab.com\/?p=770\/#%E3%81%BE%E3%81%A8%E3%82%81\" >\u307e\u3068\u3081<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%9B%AE%E7%9A%84\"><\/span>\u76ee\u7684<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>python\u3067\u306f\u7c21\u5358\u306bGUI\u3092\u4f5c\u6210\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066tkinter\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>GUI\u3092\u30ea\u30c3\u30c1\u306b\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u753b\u50cf\u3092\u4f7f\u3046\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u540c\u3058\u753b\u50cf\u3092\u305a\u3063\u3068\u8868\u793a\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u306f\u306a\u304f\u3001\u4f55\u304b\u3092\u30c8\u30ea\u30ac\u306b\u3057\u3066\u753b\u50cf\u3092\u5207\u308a\u66ff\u3048\u308b\u3068\u3044\u3046\u4ed5\u639b\u3051\u3092\u7528\u610f\u3057\u305f\u3044\u5834\u5408\u3082\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>tkinter\u3067\u306f\u3082\u3061\u308d\u3093\u753b\u50cf\u306a\u3069\u306e\u8868\u793a\u3082\u53ef\u80fd\u3067\u3059\u304c\u3001\u3053\u306e\u3088\u3046\u306a\u753b\u50cf\u306e\u5207\u308a\u66ff\u3048\u304c\u3067\u304d\u308b\u306e\u304b\u3068\u3044\u3046\u3053\u3068\u3092\u8a66\u3057\u307e\u3057\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u3044\u304d\u307e\u3059\u3002 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%BD%BF%E7%94%A8%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA\"><\/span>\u4f7f\u7528\u30e9\u30a4\u30d6\u30e9\u30ea<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4eca\u56de\u306f\u4e3b\u306b\u4ee5\u4e0b\u306e\uff13\u3064\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>tkinter<\/li><\/ul>\n\n\n\n<p>python\u4e0a\u3067GUI\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3001\u4eca\u56de\u306e\u30e1\u30a4\u30f3\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>PIL(pillow)<\/li><\/ul>\n\n\n\n<p>python\u4e0a\u3067\u753b\u50cf\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u4eca\u56de\u306f\u753b\u50cf\u3092\u4e00\u5b9a\u6642\u9593\u6bce\u306b\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u3092\u8a66\u3059\u306e\u3067\u3001\u305d\u3082\u305d\u3082\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u3093\u3067\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>threading<\/li><\/ul>\n\n\n\n<p>\u753b\u50cf\u3092\u81ea\u52d5\u5207\u63db\u3048\u3059\u308b\u4ed5\u639b\u3051\u3092\u4f5c\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002\u8a73\u3057\u304f\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001Anaconda3\u306e\u74b0\u5883\u3067\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3059\u3079\u3066import\u3067\u304d\u308b\u72b6\u614b\u306b\u306a\u3063\u3066\u307e\u3059\u306e\u3067\u3001\u65b0\u305f\u306bpip install\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step1_%E3%81%AB%E3%82%88%E3%82%8B%E7%94%BB%E5%83%8F%E8%A1%A8%E7%A4%BA\"><\/span>Step1 : \u306b\u3088\u308b\u753b\u50cf\u8868\u793a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u57fa\u672c\u7684\u306atkinter\u306e\u4f7f\u3044\u65b9\u3068\u3057\u3066\u3001\u5358\u306b\u753b\u50cf\u3092\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u306e\u95a2\u6570\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u753b\u50cf\u3092\u8868\u793a\u3055\u305b\u308b\u95a2\u6570(show_image)\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#\u5fc5\u8981\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f\nimport sys\nimport tkinter\nfrom PIL import Image, ImageTk\nimport time\n\n#\u753b\u50cf\u3092\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u306e\u95a2\u6570\u5b9a\u7fa9\ndef show_image():\n\u3000\u3000#tkinter\u306eTK\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u7528\u610f\n    root = tkinter.Tk()\n    root.title(&#039;test&#039;)\n    root.geometry(&quot;400x300&quot;)\n\n\u3000\u3000#\u753b\u50cf\u8aad\u307f\u8fbc\u307f(yourimage.jpg\u306f\u4efb\u610f\u306e\u753b\u50cf\u3078\u306e\u30d1\u30b9\u306b\u3059\u308b\u3053\u3068)\n    img = Image.open(&#039;yourimage.jpg&#039;)\n    img = ImageTk.PhotoImage(img)\n\n\u3000\u3000#Canvas\u306e\u7528\u610f\n    canvas = tkinter.Canvas(bg = &quot;black&quot;, width=400, height=300)\n    canvas.place(x=100, y=50)\n    item = canvas.create_image(30, 30, image=img, anchor=tkinter.NW)\n\n\u3000\u3000#\u8868\u793a\n    root.mainloop()\n<\/pre><\/div>\n\n\n<p>\u65b9\u91dd\u3068\u3057\u3066\u306f\u3001tkinter\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089canvas\u3092\u7528\u610f\u3057\u3066\u3001\u305d\u306e\u4e0a\u306bjpg\u30a4\u30e1\u30fc\u30b8\u3092\u8f09\u305b\u308b\u5f62\u3067\u5b9f\u73fe\u3057\u307e\u3059\u3002\u30b3\u30fc\u30c9\u4e2d\u306b\u51fa\u3066\u304f\u308bImageTk\u306fjpg\u3092\u6271\u3044\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step2_%E7%94%BB%E5%83%8F%E3%81%AE%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88\"><\/span>Step2 : \u753b\u50cf\u306e\u5207\u308a\u66ff\u3048<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4eca\u56de\u884c\u3044\u305f\u3044\u3053\u3068\u306f\u3001Step1\u3067\u4f5c\u6210\u3057\u305f\u95a2\u6570\u3067\u8868\u793a\u3057\u305f\u753b\u50cf\u3092\u81ea\u52d5\u3067\u5207\u308a\u66ff\u3048\u305f\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u4e0a\u8a18\u30b3\u30fc\u30c9\u4e2d\u306eroot.mainloop\u306b\u5165\u308b\u3068tkinter\u306egui\u4e0a\u306ebutton\u306a\u3069\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u3057\u304b\u5236\u5fa1\u3092\u53d7\u3051\u4ed8\u3051\u3066\u304f\u308c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u3088\u3046\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u5b9f\u73fe\u3057\u305f\u3044\u306e\u306f\u3001\u624b\u52d5\u3067button\u3092\u62bc\u3059\u306e\u3067\u306f\u306a\u304f\u4e00\u5b9a\u6642\u9593\u5f8c\u306b\u81ea\u52d5\u3067\u5207\u308a\u66ff\u3048\u305f\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u5c11\u3005\u529b\u696d\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001threading\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3001\u30b9\u30ec\u30c3\u30c9\u3092\u7acb\u3066\u308b\u5f62\u3067\u5de5\u592b\u3057\u307e\u3057\u305f\u3002\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport sys\nimport tkinter\nfrom PIL import Image, ImageTk\nimport threading\nimport time\n\ndef show_image():\n\u3000\u3000#\u5916\u304b\u3089\u89e6\u308c\u308b\u3088\u3046\u306b\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3067\u5b9a\u7fa9\n    global item, canvas\n\n    root = tkinter.Tk()\n    root.title(&#039;test&#039;)\n    root.geometry(&quot;400x300&quot;)\n    img = Image.open(&#039;your_image.jpg&#039;)\n    img = ImageTk.PhotoImage(img)\n    canvas = tkinter.Canvas(bg = &quot;black&quot;, width=400, height=300)\n    canvas.place(x=100, y=50)\n    item = canvas.create_image(30, 30, image=img, anchor=tkinter.NW)\n    root.mainloop()\n\n#\u30b9\u30ec\u30c3\u30c9\u3092\u7acb\u3066\u3066tkinter\u306e\u753b\u50cf\u8868\u793a\u3092\u958b\u59cb\u3059\u308b\nthread1 = threading.Thread(target=show_image)\nthread1.start()\n\n#\u5207\u308a\u66ff\u3048\u305f\u3044\u753b\u50cf\u3092\u5b9a\u7fa9\nimg2 = Image.open(&#039;your_image2.jpg&#039;)\nimg2 = ImageTk.PhotoImage(img2)\ntime.sleep(3) #3\u79d2\u6bce\u306b\u5207\u308a\u66ff\u3048\n\n#item\u3092\u5dee\u3057\u66ff\u3048\ncanvas.itemconfig(item,image=img2)\ntime.sleep(3)\n\n#item\u3092\u3082\u3068\u306b\u623b\u3059\nimg = Image.open(&#039;your_image.jpg&#039;)\nimg = ImageTk.PhotoImage(img)\ncanvas.itemconfig(item,image=img)\n<\/pre><\/div>\n\n\n<p>canvas\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3067\u5b9a\u7fa9\u3057\u305f\u4e0a\u3067\u30b9\u30ec\u30c3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u753b\u50cf\u3092\u8868\u793a\u3057\u3066\u304a\u304d\u30013\u79d2\u7d4c\u904e\u3057\u305f\u3089canvas\u5185\u306ejps\u30a4\u30e1\u30fc\u30b8\u3092\u7f6e\u304d\u63db\u3048\u3001\u307e\u305f3\u79d2\u7d4c\u904e\u3057\u305f\u3089\u3082\u3068\u306e\u753b\u50cf\u3078\u7f6e\u304d\u63db\u3048\u76f4\u3059\u3001\u3068\u3044\u3046\u65b9\u5f0f\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E3%81%BE%E3%81%A8%E3%82%81\"><\/span>\u307e\u3068\u3081<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u30b9\u30de\u30fc\u30c8\u306a\u3084\u308a\u65b9\u304b\u3069\u3046\u304b\u306f\u3055\u3066\u304a\u304d\u3001canvas\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u3067\u5b9a\u7fa9\u3057\u3066\u30b9\u30ec\u30c3\u30c9\u3067\u5b9f\u884c\u3057\u3066\u304a\u304d\u3001\u305d\u3068\u304b\u3089itemconfig\u3067\u5dee\u3057\u66ff\u3048\u308b\u3053\u3068\u3067\u3001\u4e00\u5fdc\u3084\u308a\u305f\u3044\u3053\u3068\u306f\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 python\u3067\u306f\u7c21\u5358\u306bGUI\u3092\u4f5c\u6210\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066tki&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=770","footnotes":""},"categories":[7],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=770"}],"version-history":[{"count":31,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":3811,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/770\/revisions\/3811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/1218"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}