{"id":1572,"date":"2020-08-19T00:00:00","date_gmt":"2020-08-18T15:00:00","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1572"},"modified":"2020-08-19T11:07:11","modified_gmt":"2020-08-19T02:07:11","slug":"python-tkinter-gui-programing-text-tag","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/08\/19\/python-tkinter-gui-programing-text-tag\/","title":{"rendered":"Python Tkinter GUI\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Text tag"},"content":{"rendered":"\n<p>\u3000\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>\u3000\u6c17\u304c\u4ed8\u3051\u3070\u30011\u30f6\u6708\u4ee5\u4e0a\u3082\u66f4\u65b0\u3057\u3066\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u63a1\u7528\u6d3b\u52d5\u3068\u304b\u3001\u590f\u4f11\u307f\u3068\u304b\u3001\u3082\u308d\u3082\u308d\u3042\u3063\u3066\u3001\u5fd9\u3057\u304b\u3063\u305f\u3001\u304b\u3082\u3001\u3068\u3001\u8a00\u3044\u8a33\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u3088\u304f\u3088\u304f\u8003\u3048\u3066\u307f\u308b\u3068\u3001Amazon\u30d7\u30e9\u30a4\u30e0\u3067\u6d77\u5916\u30c9\u30e9\u30de\u306e\u300cElementary\u300d\u3092\u305a\u3063\u3068\u898b\u3066\u3044\u305f\u306e\u304c\u539f\u56e0\u3067\u3059\u3002\u3059\u307f\u307e\u305b\u3093\u3002\u8a00\u3044\u8a33\u306f\u3088\u304f\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u6c17\u3092\u53d6\u308a\u76f4\u3057\u3066\u3002\u3053\u3053\u306e\u3068\u3053\u308d\u53d6\u308a\u7d44\u3093\u3067\u3044\u305ftkinter\u306e\u4e2d\u306b\u3061\u3087\u304f\u3061\u3087\u304f\u767b\u5834\u3057\u3066\u304f\u308b\u30bf\u30b0\uff08tag\uff09\u306e\u8003\u3048\u65b9\u3067\u3061\u3087\u3063\u3068\u6c17\u306b\u306a\u3063\u305f\u3053\u3068\u3092\u8abf\u3079\u308b\u305f\u3081\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002\u4eca\u56de\u306fText\u3067\u4f7f\u308f\u308c\u308b\u30bf\u30b0\u306b\u3064\u3044\u3066\u3001\u3067\u3059\u3002\u30bf\u30b0\u306f\u901a\u5e38\u3001Text\u306e\u6587\u5b57\u5217\u306b\u8272\u3092\u4ed8\u3051\u305f\u308a\u30d5\u30a9\u30f3\u30c8\u3092\u5909\u3048\u305f\u308a\u3059\u308b\u306e\u306b\u3064\u304b\u3044\u307e\u3059\u3002\u6c17\u306b\u306a\u308a\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u540c\u3058\u6587\u5b57\u5217\u306b\u30bf\u30b0\u3092\u30bb\u30c3\u30c8\u3057\u305f\u3068\u304d\u3001\u3069\u3061\u3089\u304c\u6709\u52b9\u306b\u306a\u308b\u306e\u304b\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u6025\u3044\u3067\u3044\u308b\u65b9\u306e\u305f\u3081\u306b\u7d50\u8ad6\u3092\u8a00\u3044\u307e\u3059\u3068\u3001\u30bf\u30b0\u306f\u8a2d\u5b9a\u3057\u305f\u9806\u306b\u7a4d\u307e\u308c\u3066\u3044\u304d\u3001\u6700\u5f8c\u306e\u8a2d\u5b9a\u304c\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002\u524d\u306b\u8a2d\u5b9a\u3057\u305f\u3082\u306e\u3092\u512a\u5148\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u7a4d\u3093\u3060\u9806\u3092\u5165\u308c\u66ff\u3048\u308c\u3070\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u3067\u304d\u3042\u304c\u308a\u30a4\u30e1\u30fc\u30b8<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"839\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image.png\" alt=\"\" class=\"wp-image-1573\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image.png 806w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image-288x300.png 288w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image-768x799.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>\u30bf\u30b0\u306e\u512a\u5148\u9806\u4f4d\u3092\u5909\u66f4\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0<\/figcaption><\/figure>\n\n\n\n<p>\u3000\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4e0a\u90e8\u306e\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u3001\u8d64\u3001\u7dd1\u3001\u9752\u306e\u6587\u5b57\u5217\u304c\u521d\u671f\u5024\u3068\u3057\u3066\u8868\u793a\u3055\u308c\u305f\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u300cSet Color\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3053\u3068\u3067\u3001\u771f\u3093\u4e2d\u306e\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u3067\u9078\u629e\u3057\u305f\u8272\u3092\u3001\u9078\u629e\u3057\u305f\u6587\u5b57\u5217\u306e\u6587\u5b57\u8272\uff08foreground\uff09\u304b\u80cc\u666f\u8272\uff08background\uff09\u306b\u3001\u30bf\u30b0\u3068\u8272\u3092\u4ed8\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u4e0b\u90e8\u306e\u4e00\u89a7\u306f\u3001\u30bf\u30b0\u4e00\u89a7\u3067\u3059\u3002\u884c\u3092\u9078\u629e\u3057\u3066\u3001\u300c\u2191\u300d\u3001\u300c\u2193\u300d\u3067\u30bf\u30b0\u3092\u4e0a\u4e0b\u306b\u79fb\u52d5\u3001\u300cDEL\u300d\u30dc\u30bf\u30f3\u3067\u30bf\u30b0\u3092\u524a\u9664\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u30dc\u30bf\u30f3\u3067\u30bf\u30b0\u3092\u4e0a\u4e0b\u3059\u308b\u3053\u3068\u3067\u512a\u5148\u9806\u4f4d\u304c\u5909\u308f\u3063\u305f\u6642\u306e\u6319\u52d5\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u884c\u306e\u5185\u8a33\u306f\u3001\u5de6\u5074\u304c\u30bf\u30b0\u540d\u3067\u3001\u62ec\u5f27\u306e\u4e2d\u304c[\u958b\u59cb &#8211; \u7d42\u4e86]\u3092\u8868\u3057\u307e\u3059\u3002\u4e2d\u306e\u6570\u5b57\u306f\u3001\u300c\u884c.\u5217\u300d\u3092\u8868\u3057\u3066\u3044\u3066\u3001\u884c\u306f1\u30aa\u30ea\u30b8\u30f3\u3001\u5217\u306f0\u30aa\u30ea\u30b8\u30f3\u306e\u6570\u5024\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30bf\u30b0\u4e00\u89a7\u306e\u4e2d\u306b\u3042\u308b\u300csel\u300d\u306f\u3001\u7279\u6b8a\u306a\u30bf\u30b0\u3067\u3001\u81ea\u52d5\u7684\u306b\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u73fe\u5728\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u7bc4\u56f2\u3092\u8868\u3059\u30bf\u30b0\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\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\nfrom tkinter import colorchooser\n\n\nclass Application(tk.Tk):\n    ''' Text\u30bf\u30b0\u306e\u512a\u5148\u9806\u4f4d\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002\n    \u30bf\u30b0\u3092\u30bb\u30c3\u30c8\u3059\u308b\u305f\u3081\u306eText\u306e\u4f5c\u6210\u3002\n    \u8272\u3092\u30bb\u30c3\u30c8\u3059\u308b\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u306e\u4f5c\u6210\u3002\n    \u30bf\u30b0\u306e\u5185\u5bb9\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306e\u30ea\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3002\n    \u30ea\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u540d\u524d\u3092\u79fb\u52d5\u3057\u305f\u308a\u524a\u9664\u3057\u305f\u308a\u3059\u308b\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c\u6210\u3002\n    '''\n    def __init__(self):\n        super().__init__()\n        self.title(\"Tag Priority\")\n\n        self.text = tk.Text(self)\n        self.text.pack()\n        self.text.bind(\"&lt;KeyRelease>\", self.refresh_list)\n        self.text.bind(\"&lt;ButtonRelease>\", self.refresh_list)\n\n        frame = tk.Frame(self)\n        self.color = tk.StringVar(value=\"red\")\n        radio_red = tk.Radiobutton(frame, text=\"Red\",\n                                   variable=self.color, value=\"red\")\n        radio_red.pack(side=tk.LEFT)\n        radio_green = tk.Radiobutton(frame, text=\"Green\",\n                                     variable=self.color, value=\"green\")\n        radio_green.pack(side=tk.LEFT)\n        radio_blue = tk.Radiobutton(frame, text=\"Blue\",\n                                    variable=self.color, value=\"blue\")\n        radio_blue.pack(side=tk.LEFT)\n        radio_color = tk.Radiobutton(frame, text=\"Color\",\n                                     variable=self.color, value=\"color\",\n                                     command=self.set_palet_color)\n        radio_color.pack(side=tk.LEFT)\n\n        self.color_palette = tk.Canvas(frame, width=20, height=20,\n                                       background=\"white\")\n        self.color_palette.pack(side=tk.LEFT)\n        self.color_palette.bind(\"&lt;Button-1>\", self.set_palet_color, add=True)\n\n        self.option = tk.StringVar(self)\n        self.option.set(\"foreground\")\n        combo = tk.OptionMenu(frame, self.option,\n                              *{\"foreground\", \"background\"})\n        combo.pack(side=tk.LEFT)\n\n        button = tk.Button(frame, text=\"Set Color\",\n                           command=self.set_color)\n        button.pack(side=tk.RIGHT)\n        frame.pack()\n\n        self.list = tk.Listbox(self)\n        self.list.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)\n\n        updown_frame = tk.Frame(self)\n        up_button = tk.Button(updown_frame, text=\"\u2191\", command=self.tag_up)\n        up_button.pack()\n        del_button = tk.Button(updown_frame, text=\"DEL\", command=self.tag_del)\n        del_button.pack()\n        down_button = tk.Button(updown_frame, text=\"\u2193\", command=self.tag_down)\n        down_button.pack()\n        updown_frame.pack(side=tk.LEFT)\n\n        # \u30c6\u30ad\u30b9\u30c8\u306e\u521d\u671f\u5024\n        self.text.insert(1.0, \"*****Red******\\n*****Green****\\n*****Blue*****\")\n        self.text.tag_add(\"red\", 1.0, \"1.end\")\n        self.text.tag_config(\"red\", foreground=\"red\")\n        self.text.tag_add(\"green\", 2.0, \"2.end\")\n        self.text.tag_config(\"green\", foreground=\"green\")\n        self.text.tag_add(\"blue\", 3.0, \"3.end\")\n        self.text.tag_config(\"blue\", foreground=\"blue\")\n\n        self.refresh_list()\n\n    def set_color(self):\n        ''' \u9078\u629e\u3055\u308c\u305fText\u306e\u6587\u5b57\u5217\u306b\u8272\u3092\u4ed8\u3051\u307e\u3059\u3002 '''\n        tag_range = self.text.tag_ranges('sel')\n        if not tag_range:\n            return\n        option = self.option.get()\n        color = self.color.get()\n        if color == \"color\":\n            color = self.color_palette.cget(\"background\")\n        tagname = \"t_\"+option+\"_\"+color+\"_\"+str(len(self.text.tag_names()))\n        self.text.tag_add(tagname, *tag_range)\n        self.text.tag_config(tagname, {option: color})\n        self.refresh_list()\n        for tag_name in reversed(self.text.tag_names()):\n            print(tag_name, self.text.tag_ranges(tag_name))\n\n    def refresh_list(self, event=None):\n        ''' \u30ea\u30b9\u30c8\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002 '''\n        # pylint: disable=unused-argument\n        self.list.delete(0, tk.END)\n        for i, tag in enumerate(reversed(self.text.tag_names())):\n            tag_range = self.text.tag_ranges(tag)\n            if tag_range:\n                self.list.insert(i, tag + f\"[{tag_range[0]} - {tag_range[1]}]\")\n            else:\n                self.list.insert(i, tag + \"[\u672a\u9078\u629e]\")\n\n    def tag_up(self):\n        ''' \u30bf\u30b0\u3092\u4e00\u884c\u4e0a\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002'''\n        self.tag_move(-1)\n\n    def tag_down(self):\n        ''' \u30bf\u30b0\u3092\u4e00\u884c\u4e0b\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002'''\n        self.tag_move(1)\n\n    def tag_move(self, offset):\n        ''' \u30bf\u30b0\u3092\u79fb\u52d5\u3057\u307e\u3059\u3002'''\n        active_position = self.list.index(tk.ACTIVE)\n        active_value = self.list.get(tk.ACTIVE)\n        self.list.delete(active_position)\n        self.list.insert(active_position + offset, active_value)\n        self.list.activate(active_position + offset)\n        self.list.see(active_position + offset)\n\n        active_tag = active_value.split(\"[\")[0]\n        above_or_below_tag = self.list.get(active_position).split(\"[\")[0]\n        if offset == 1:\n            self.text.tag_lower(active_tag, above_or_below_tag)\n        else:\n            self.text.tag_raise(active_tag, above_or_below_tag)\n        print('*'*20)\n        for tag_name in reversed(self.text.tag_names()):\n            print(tag_name, self.text.tag_ranges(tag_name))\n        print('*'*20)\n\n    def set_palet_color(self, event=None):\n        ''' \u30d1\u30ec\u30c3\u30c8\u306e\u8272\u3092\u30bb\u30c3\u30c8\u3059\u308b\u305f\u3081\u306e\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u547c\u3073\u51fa\u3057\u3001\u53d6\u5f97\u3057\u305f\u8272\u3092\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002 '''\n        # pylint: disable=unused-argument\n        initial_color = self.color_palette.cget(\"background\")\n        color = colorchooser.askcolor(color=initial_color)\n        if color:\n            print(color)\n            self.color_palette.configure(background=color[1])\n        self.color.set(\"color\")\n\n    def tag_del(self):\n        ''' \u30ea\u30b9\u30c8\u3067\u9078\u629e\u3055\u308c\u305f\u30bf\u30b0\u3092\u524a\u9664\u3057\u307e\u3059\u3002'''\n        active_position = self.list.index(tk.ACTIVE)\n        active_value = self.list.get(tk.ACTIVE)\n        self.list.delete(active_position)\n\n        active_tag = active_value.split(\"[\")[0]\n        self.text.tag_delete(active_tag)\n\n\ndef main():\n    ''' \u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0(\u547c\u3073\u51fa\u3057\u7528) '''\n    main_application = Application()\n    main_application.mainloop()\n\n\nif __name__ == \"__main__\":\n    main()\n<\/pre>\n\n\n\n<p>\u3000\u4eca\u56de\u306f\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306bpylint\u3067\u9759\u7684\u30b3\u30fc\u30c9\u5206\u6790\u3092\u5b9f\u65bd\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u610f\u5916\u3068\u3044\u308d\u3044\u308d\u3068\u3046\u308b\u3055\u304f\u3066\u3001\u30af\u30e9\u30b9\u30c9\u30ad\u30e5\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u6587\u5b57\u5217\u304c\u306a\u3044\u3001\u30e1\u30bd\u30c3\u30c9\u30c9\u30ad\u30e5\u30e1\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\u6587\u5b57\u5217\u304c\u306a\u3044\u3001\u5909\u6570\u540d\u3001\u30e1\u30bd\u30c3\u30c9\u540d\u306e\u30eb\u30fc\u30eb\u304c\u304a\u304b\u3057\u3044\u3001\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u5f15\u6570\u304c\u3042\u308b\u3001\u30ab\u30f3\u30de\u306e\u5f8c\u308d\u306b\u7a7a\u767d\u304c\u306a\u3044\u3001\u30b3\u30ed\u30f3\u306e\u5f8c\u308d\u306b\u7a7a\u767d\u304c\u306a\u3044\u3001\u7a7a\u884c\u304c\u8db3\u308a\u306a\u3044\u3001\u7b49\u3005\u3001\u3044\u308d\u3044\u308d\u3068\u3054\u6307\u6458\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306e\u63d0\u6848\u3082\u3057\u3066\u304f\u308c\u3066\u3044\u3066\u3001\u30af\u30e9\u30b9\u306e\u30a2\u30c8\u30ea\u30d3\u30e5\u30fc\u30c8\u304c\u591a\u3059\u304e\u308b\u306e\u3067\u3001\u898b\u76f4\u3057\u305f\u65b9\u304c\u3088\u3044\u3067\u3059\u3088\u3001\u3068\u3001\u8a00\u308f\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u8aac\u660e<\/h2>\n\n\n\n<p>\u300012\u884c\u76ee\u3001__init__(self)\u3067\u3053\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u5168\u4f53\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u300216\uff5e19\u884c\u76ee\u3067Text\u3092\u4f5c\u6210\u3001\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u30a4\u30d9\u30f3\u30c8\u306e&lt;KeyRelease&gt;&lt;ButtonRelease&gt;\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u3001\u4e00\u89a7\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u4f55\u3089\u304b\u306e\u30ad\u30fc\u5165\u529b\u304c\u7d42\u4e86\u3057\u305f\u3068\u304d\u304b\u3001\u30de\u30a6\u30b9\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u304c\u7d42\u308f\u3063\u305f\u6642\u306b\u3001refresh_list()\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300021\uff5e51\u884c\u76ee\u3001\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u3001\u30ab\u30e9\u30fc\u30d1\u30ec\u30c3\u30c8\u306e\u30ad\u30e3\u30f3\u30d0\u30b9\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u30e1\u30cb\u30e5\u30fc\u3001\u300cSet color\u300d\u30dc\u30bf\u30f3\u3092\u4f5c\u3063\u3066\u3044\u307e\u3059\u3002\u7279\u306b34\u884c\u76ee\u306e\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u300cColor\u300d\u304c\u62bc\u3055\u308c\u305f\u3068\u304d\u306f\u30ab\u30e9\u30fc\u30d1\u30ec\u30c3\u30c8\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u300ccommand=self.set_palet_color\u300d\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u306e\u90e8\u5206\u306f\u3001\u3082\u305740\u884c\u76ee\u306ebind\u3068\u540c\u3058\u3088\u3046\u306b\u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u306b\u5b9a\u7fa9\u3057\u3066\u3057\u307e\u3046\u3068\u3001\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u304c\u9078\u629e\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u306e\u3067\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u300053\u300154\u884c\u76ee\u3001\u30ea\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u300156\uff5e63\u884c\u76ee\u3067\u3001\u300c\u2191\u300d\u300cDEL\u300d\u300c\u2193\u300d\u306e\u30dc\u30bf\u30f3\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300065\uff5e72\u884c\u76ee\u3067Text\u306e\u521d\u671f\u5024\u3092\u30bf\u30b0\u4ed8\u304d\u306e\u8272\u3092\u30bb\u30c3\u30c8\u3057\u3066\u300174\u884c\u76ee\u3067\u30ea\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u300076\uff5e90\u884c\u306f\u3001set_color()\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u9078\u629e\u3055\u308c\u305f\u30c6\u30ad\u30b9\u30c8\u306e\u7bc4\u56f2\u306b\u30bf\u30b0\u3092\u5b9a\u7fa9\u3057\u3064\u3064\u8272\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u307e\u3059\u3002\u73fe\u5728\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u7bc4\u56f2\u3092\u53d6\u5f97\u3059\u308b\u306e\u306b\u3001\u300c<code>tag_range = self.text.tag_ranges('sel')<\/code>\u300d\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002&#8217;sel&#8217;\u306f\u300ctk.SEL\u300d\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u5229\u7528\u3057\u305f\u65b9\u304c\u3088\u304b\u3063\u305f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<code>tag_ranges()<\/code>\u3067\u7bc4\u56f2\u304c\u53d6\u5f97\u3067\u304d\u306a\u3044\u3068\u30bf\u30b0\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3068\u304d\u306b\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u307e\u3059\u3002<br>\u300089\u884c\u76ee\u3001<code>self.text.tag_names()<\/code>\u3067\u30bf\u30b0\u540d\u306e\u4e00\u89a7\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u304c\u3001\u4f5c\u6210\u3057\u305f\u9806\u756a\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u304f\u306e\u3067\u3001\u30b9\u30bf\u30c3\u30af\u3055\u308c\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u306b\u5408\u3044\u307e\u305b\u3093\u3002\u306a\u306e\u3067\u3001\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u306ereversed()\u3092\u4f7f\u3063\u3066\u9006\u9806\u30ea\u30b9\u30c8\u3092\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000103\uff5e129\u884c\u76ee\u307e\u3067\u3001\u30bf\u30b0\u304c\u79fb\u52d5\u3067\u304d\u308b\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u30dd\u30a4\u30f3\u30c8\u306f123\u884c\u76ee\u3068125\u884c\u76ee\u306e<code>self.text.tag_lower(active_tag, above_or_below_tag)<\/code>\u3001<code>self.text.tag_raise(active_tag, above_or_below_tag)<\/code>\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u4e8c\u3064\u76ee\u306e\u5f15\u6570\u304c\u306a\u3044\u3068\u4e00\u756a\u4e0a\u304b\u4e00\u756a\u4e0b\u307e\u3067\u30bf\u30b0\u304c\u79fb\u52d5\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002\u4e0a\u4e0b\u30dc\u30bf\u30f3\u3067\u3072\u3068\u3064\u305a\u3064\u79fb\u52d5\u3057\u3066\u307b\u3057\u304b\u3063\u305f\u306e\u3067\u3002\u4e8c\u3064\u76ee\u306e\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30bf\u30b0\u306e\u4e0b\u3001\u307e\u305f\u306f\u4e0a\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000131\uff5e139\u884c\u76ee\u306f\u30ab\u30e9\u30fc\u3092\u9078\u629e\u3057\u3066\u3082\u3089\u3046\u305f\u3081\u306e\u30ab\u30e9\u30fc\u30d1\u30ec\u30c3\u30c8\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u306e\u300ccolor\u300d\u3092\u9078\u629e\u3059\u308b\u304b\u3001\u8272\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a6\u30a3\u30f3\u30c9\u30a6\u3067\u8272\u3092\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u5358\u306b<code>color = colorchooser.askcolor(color=initial_color)<\/code>\u3068\u3001\u547c\u3073\u51fa\u3059\u3060\u3051\u3067\u4f7f\u3048\u307e\u3059\u3002\u3042\u3001<code>colorchooser<\/code>\u306f\u3001\u5148\u982d\u306e\u65b9\u3067<code>from tkinter import colorchooser<\/code>\u3068\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"757\" height=\"621\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image-1.png\" alt=\"\" class=\"wp-image-1577\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image-1.png 757w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2020\/08\/image-1-300x246.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><figcaption>\u8272\u306e\u8a2d\u5b9a\u30c0\u30a4\u30a2\u30ed\u30b0<\/figcaption><\/figure>\n\n\n\n<p>\u3000141\uff5e148\u884c\u76ee\u307e\u3067\u3001\u30bf\u30b0\u3092\u524a\u9664\u3057\u3066\u3044\u307e\u3059\u3002\u30ea\u30b9\u30c8\u304b\u3089\u306f\u3001<code>self.list.delete(active_position)<\/code>\u3092\u4f7f\u3063\u3066\u524a\u9664\u3057\u3066\u3001\u30bf\u30b0\u306e\u4e00\u89a7\u304b\u3089\u306f<code>self.text.tag_delete(active_tag)<\/code>\u3067\u30bf\u30b0\u3092\u53d6\u308a\u9664\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000151\uff5e154\u884c\u76ee\u306f\u3001main()\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u307e\u3067\u306f\u3001<code>main_application = Application()<\/code>\u306e\u884c\u3092\u3001<code>if __name__ == \"__main__\":<\/code>\u306e\u4e0b\u3078\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u305d\u308c\u3060\u3068pylint\u306b\u53f1\u3089\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u3066\u3002\u306a\u3093\u3068\u3001\u30b3\u30f3\u30b9\u30bf\u30f3\u30c8\u5024\u306e\u5909\u6570\u540d\u306f\u3001UPPER_CASE\u306e\u5f62\u5f0f\u3067\u5ba3\u8a00\u3059\u308b\u3053\u3068\u304c\u671b\u307e\u3057\u3044\u3068\u306e\u3053\u3068\u3067\u3059\u3002Python\u306b\u306f\u30b3\u30f3\u30b9\u30bf\u30f3\u30c8\u5024\u3068\u3044\u3046\u8003\u3048\u65b9\u304c\u306a\u3044\u306e\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u30ec\u30d9\u30eb\u306e\u5909\u6570\u306f\u3059\u3079\u3066\u30b3\u30f3\u30b9\u30bf\u30f3\u30c8\u5024\u3067\u3057\u3087\u3001\u3068\u3044\u3046\u3075\u3046\u306b\u8003\u3048\u3089\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002main()\u95a2\u6570\u306e\u4e2d\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u30ec\u30d9\u30eb\u306e\u5909\u6570\u306b\u306a\u308b\u3053\u3068\u3092\u907f\u3051\u308b\u3001\u3068\u3044\u3046\u306e\u304c\u4e00\u822c\u7684\u306a\u89e3\u6c7a\u65b9\u6cd5\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3000\u4eca\u56de\u306fText\u3067\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u30bf\u30b0\u3092\u8abf\u3079\u307e\u3057\u305f\u3002\u30bf\u30b0\u3092\u4f7f\u3046\u3068\u30c6\u30ad\u30b9\u30c8\u306e\u6587\u5b57\u8272\u3084\u3001\u80cc\u666f\u8272\u3001\u30d5\u30a9\u30f3\u30c8\u306e\u8a2d\u5b9a\u306a\u3069\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u8907\u6570\u306e\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u306e\u512a\u5148\u9806\u4f4d\u306f\u6700\u5f8c\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u30bf\u30b0\u306e\u65b9\u304c\u512a\u5148\u3055\u308c\u307e\u3059\u3002\u3042\u3068\u304b\u3089<code>tag_raise()<\/code>\u30e1\u30bd\u30c3\u30c9\u3001<code>tag_lower()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u512a\u5148\u9806\u4f4d\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\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 \u3000\u6c17\u304c\u4ed8\u3051\u3070\u30011\u30f6\u6708\u4ee5\u4e0a\u3082\u66f4\u65b0\u3057\u3066\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u63a1\u7528\u6d3b\u52d5\u3068\u304b\u3001\u590f\u4f11\u307f\u3068\u304b\u3001\u3082\u308d\u3082\u308d\u3042\u3063\u3066\u3001\u5fd9\u3057\u304b\u3063\u305f\u3001\u304b\u3082\u3001\u3068\u3001\u8a00\u3044\u8a33\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u3088\u304f\u3088\u304f\u8003\u3048\u3066\u307f\u308b\u3068\u3001A &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/08\/19\/python-tkinter-gui-programing-text-tag\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python Tkinter GUI\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Text tag&#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-1572","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\/1572","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=1572"}],"version-history":[{"count":9,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1572\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1572\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}