{"id":1125,"date":"2020-04-19T00:00:35","date_gmt":"2020-04-18T15:00:35","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1125"},"modified":"2020-05-02T14:53:29","modified_gmt":"2020-05-02T05:53:29","slug":"python-tkinter-gui-programing-canvas-text","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/04\/19\/python-tkinter-gui-programing-canvas-text\/","title":{"rendered":"Python tkinter GUI \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Canva\u306eText\u306b\u3064\u3044\u3066"},"content":{"rendered":"\n<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000Canvas\u306b\u30c6\u30ad\u30b9\u30c8\u3092\u66f8\u3044\u305f\u3068\u304d\u306b\u3001\u305d\u306e\u5927\u304d\u3055\u3084\u3001\u5ea7\u6a19\u306f\u3069\u3046\u306a\u308b\u306e\u304b\u306a\u3001\u3068\u3001\u3061\u3087\u3063\u3068\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002<a href=\"https:\/\/anzeljg.github.io\/rin2\/book2\/2405\/docs\/tkinter\/index.html\" class=\"aioseop-link\">\u3053\u3061\u3089\u306e\u30b5\u30a4\u30c8<\/a>\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u51fa\u529b\u30a4\u30e1\u30fc\u30b8<\/h2>\n\n\n\n<p>\u3000\u51fa\u529b\u30a4\u30e1\u30fc\u30b8\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"348\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/04\/image-29.png\" alt=\"\" class=\"wp-image-1126\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/04\/image-29.png 602w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/04\/image-29-300x173.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><figcaption>tkinter\u306eCanvas\u306b\u3066\u30c6\u30ad\u30b9\u30c8\u3092\u51fa\u529b\u3057\u305f\u3068\u3053\u308d<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n\n\n\n<p>\u3000\u4eca\u56de\u4f5c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import tkinter as tk\n\nclass App(tk.Tk):\n    def __init__(self):\n        super().__init__()\n        self.title(\"Canvas Text\")\n        self.geometry(\"400x200\")\n        \n        c = tk.Canvas(self, bg=\"white\")\n        c.pack(fill=tk.BOTH)\n        \n        t1 = c.create_text(70, 30, text=\"1st text\", font=(\"\",24))\n        c.create_rectangle(c.bbox(t1))\n        x0, y0, x1, y1 = c.bbox(t1)\n        c.create_line(x1, y1, x1 + 30, y1 + 30, arrow=tk.FIRST)\n        description = \"bbox\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u3092\u56f2\u3080\u7bb1\u306e\u5ea7\u6a19\u3092\u623b\u3057\u307e\u3059\u3002\"\n        c.create_text(x1 + 30, y1 + 30, text=description, anchor=tk.W)\n        x, y = c.coords(t1)\n        c.create_line(x, y, x + 70, y + 70, arrow=tk.FIRST, fill=\"red\")\n        description = \"coords\u306f\u4e2d\u5fc3\u70b9\u3092\u623b\u3057\u307e\u3059\u3002\"\n        c.create_text(x + 70, y + 70, text=description, anchor=tk.NW, font=(\"\",9))\n        width = tk.font.Font(c,font=(\"\",9)).measure(description)\n        height = tk.font.Font(c,font=(\"\",9)).metrics(\"linespace\")\n        c.create_line(x + 70, y + 70 + height, x + 70 + width, y + 70 + height)\n        \nif __name__ == \"__main__\":\n    app = App()\n    app.mainloop()\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u8aac<\/h2>\n\n\n\n<p>\u3000\u3082\u308d\u3082\u308d\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u3064\u304f\u308b\u3068\u3053\u308d\u306f\u7aef\u6298\u3063\u3066\u3001\u307e\u305a\u306f9\u884c\u76ee\u3067\u30ad\u30e3\u30f3\u30d0\u30b9\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u4f5c\u6210\u6642\u306ebg=&#8221;white&#8221;\u3067\u80cc\u666f\u8272\u3092\u767d\u306b\u3001pack\u306efill=tk.BOTH\u3067\u30a6\u30a3\u30f3\u30c9\u30a6\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300012\u884c\u76ee\u3067&#8221;1st text&#8221;\u3068\u6700\u521d\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u5ea7\u6a19\u306bx=70\u3001y=30\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u3061\u3087\u3063\u3068\u5927\u304d\u3081\u306b\u306a\u308b\u3088\u3046\u306b\u30d5\u30a9\u30f3\u30c8\u306e\u30b5\u30a4\u30ba\u309224\u3068\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u30d5\u30a9\u30f3\u30c8\u540d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001\u521d\u671f\u5024\u306e\u307e\u307e\u306b\u3057\u3066\u304a\u304d\u305f\u304b\u3063\u305f\u306e\u3067\u3001&#8221;&#8221;\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300013\u884c\u76ee\u306ecreate_rectangle\u3092\u4f7f\u3063\u3066\u3001\u77e9\u5f62\u3092\u63cf\u753b\u3057\u3066\u3044\u307e\u3059\u3002\u6307\u5b9a\u3059\u308b\u5ea7\u6a19\u306fbbox\u3067\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u304c\u3001bbox\u306f\u30c6\u30ad\u30b9\u30c8\u3092\u56f2\u3080\u77e9\u5f62\u306e\u5de6\u4e0a\u306e\u5ea7\u6a19\u3068\u53f3\u4e0b\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3057\u307e\u3059\u300214\u884c\u76ee\u3067\u306f\u8aac\u660e\u7528\u306e\u7dda\u3092\u5f15\u304f\u305f\u3081\u306b\u3001\u3082\u3046\u4e00\u5ea6bbox\u3092\u547c\u3073\u51fa\u3057\u3066\u5ea7\u6a19\u3092\u30a2\u30f3\u30d1\u30c3\u30af\u3057\u3066\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u307c\u304f\u306e\u74b0\u5883\u3067\u306f\u3001\u305d\u308c\u305e\u308c\u3001(17, 14, 124, 47)\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u300015\u884c\u76ee\u3067\u77e2\u5370\u4ed8\u304d\u306e\u76f4\u7dda\u3092\u659c\u3081\u4e0b\u306b\u5f3e\u3044\u3066\u3044\u307e\u3059\u3002arrow=tk.FIRST\u3067\u958b\u59cb\u5ea7\u6a19\u304c\u77e2\u5370\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300018\u884c\u76ee\u3067coords\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u30c6\u30ad\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u6307\u5b9a\u3057\u305f\u5ea7\u6a19\u3092\u623b\u3057\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u306f\u30c6\u30ad\u30b9\u30c8\u306e\u4e2d\u5fc3\u70b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u4f5c\u6210\u6642\u306banchor\u3092\u6307\u5b9a\u3057\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306etk.CENTER\u304c\u6307\u5b9a\u3055\u308c\u305f\u305f\u3081\u3067\u3059\u3002\u4ed6\u306b\u3069\u3053\u3092\u6307\u5b9a\u3059\u308b\u304b\u3068\u3044\u3046\u306e\u306f\u3001<a href=\"https:\/\/anzeljg.github.io\/rin2\/book2\/2405\/docs\/tkinter\/anchors.html\" class=\"aioseop-link\">\u3053\u3061\u3089<\/a>\u304c\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u3061\u306a\u307f\u306b\u307c\u304f\u306e\u74b0\u5883\u3067\u306f\u3053\u306ecoords\u306e\u623b\u308a\u5024\u3001\u30c6\u30ad\u30b9\u30c8\u4f5c\u6210\u6642\u306e\u5ea7\u6a19\u306b70\u306830\u3092\u6307\u5b9a\u3057\u305f\u7d50\u679c\u3001\uff0870.0\u300130.0\uff09\u306b\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u3002coords\u306f\u5c0f\u6570\u70b9\u4ee5\u4e0b\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u8a66\u3057\u306bcreate_text\u306e\u5ea7\u6a19\u309270.5\u3068\u304b\u300170.9999\u3068\u304b\u306b\u8a2d\u5b9a\u3057\u305f\u3089\u3001\u305d\u306e\u5024\u3092\u304d\u3061\u3093\u3068\u4fdd\u6301\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002\u6709\u52b9\u6841\u6570\u304c\u3069\u308c\u304f\u3089\u3044\u306a\u306e\u304b\u3001\u3069\u3046\u3084\u3063\u3066\u3053\u306e\u5ea7\u6a19\u5024\u3092\u6271\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u3061\u3087\u3063\u3074\u308a\u6c17\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300022\u884c\u76ee\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u51fa\u529b\u306e\u6a2a\u5e45\u3092\u3069\u3046\u3084\u3063\u3066\u8a08\u7b97\u3059\u308c\u3070\u3044\u3044\u306e\u304b\u3001\u3068\u3044\u3046\u306e\u3092\u8abf\u3079\u305f\u7d50\u679c\u3067\u3059\u3002\u3053\u308c\u306f\u3042\u3061\u3053\u3061\u63a2\u3057\u307e\u308f\u3063\u3066\u3001\u7d50\u5c40<a href=\"https:\/\/stackoverflow.com\/questions\/53449660\/tkinter-canvas-create-text-size-python3\" class=\"aioseop-link\">\u3053\u3053<\/a>\u3092\u53c2\u8003\u306b\u3057\u305f\u3068\u601d\u3044\u307e\u3059\u3002\u30c6\u30ad\u30b9\u30c8\u306b\u4e0b\u7dda\u3092\u5f15\u3044\u3066\u3061\u3083\u3093\u3068\u5e45\u304c\u4e00\u81f4\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002\u6700\u521d\u306ffont=(&#8220;&#8221;,9)\u3068\u3044\u3046\u306e\u3092\u6307\u5b9a\u3057\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u305d\u3046\u3059\u308b\u3068\u3001\u6700\u521d\u306bcreate_text\u3057\u305f\u6642\u306e\u30b5\u30a4\u30ba\u300124\u304c\u306a\u305c\u304b\u53d6\u5f97\u3067\u304d\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u30c6\u30ad\u30b9\u30c8\u3068\u3068\u3082\u306b\u308f\u3056\u308f\u3056\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u3068\u308a\u3042\u3048\u305a\u5e45\u304c\u6c42\u307e\u3063\u3066\u6e80\u8db3\u3057\u305f\u306e\u3067\u3001\u306a\u305c\u305d\u3093\u306a\u3053\u3068\u306b\u306a\u308b\u306e\u304b\u3068\u3044\u3046\u539f\u56e0\u307e\u3067\u306f\u8abf\u67fb\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000bbox\u304c\u3042\u308b\u306e\u3067\u3044\u3063\u305f\u3093\u51fa\u529b\u3057\u3066\u3057\u307e\u3048\u3070\u30c6\u30ad\u30b9\u30c8\u306e\u63cf\u753b\u5e45\u306f\u5ea7\u6a19\u304b\u3089\u8a08\u7b97\u3067\u304d\u308b\u306e\u3067\u3059\u3051\u3069\u3001\u5e45\u3092\u3082\u3068\u306b\u4f4d\u7f6e\u6c7a\u3081\u3092\u3057\u305f\u3044\u8981\u671b\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u5148\u306b\u8a08\u7b97\u3057\u3066\u6c42\u3081\u308b\u65b9\u6cd5\u3092\u63a2\u3057\u51fa\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3000\u3053\u308c\u3067\u30ad\u30e3\u30f3\u30d0\u30b9\u4e0a\u306b\u30c6\u30ad\u30b9\u30c8\u3068\u7dda\u3092\u81ea\u7531\u81ea\u5728\u306b\u3072\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u3044\u3084\u3001\u306a\u3063\u305f\u306f\u305a\u3067\u3059\uff01(\u7b11)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002 \u3000Canvas\u306b\u30c6\u30ad\u30b9\u30c8\u3092\u66f8\u3044\u305f\u3068\u304d\u306b\u3001\u305d\u306e\u5927\u304d\u3055\u3084\u3001\u5ea7\u6a19\u306f\u3069\u3046\u306a\u308b\u306e\u304b\u306a\u3001\u3068\u3001\u3061\u3087\u3063\u3068\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\u3053\u3061\u3089\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/04\/19\/python-tkinter-gui-programing-canvas-text\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python tkinter GUI \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Canva\u306eText\u306b\u3064\u3044\u3066&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13,2],"tags":[],"class_list":["post-1125","post","type-post","status-publish","format-standard","hentry","category-program","category-tkinter","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/comments?post=1125"}],"version-history":[{"count":3,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1125\/revisions"}],"predecessor-version":[{"id":1209,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1125\/revisions\/1209"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}