{"id":4709,"date":"2024-10-07T15:50:27","date_gmt":"2024-10-07T14:50:27","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4709"},"modified":"2025-12-09T11:16:20","modified_gmt":"2025-12-09T11:16:20","slug":"label","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/gui\/tkinter-tk-gui-toolkit\/gui-objects\/label","title":{"rendered":"Label"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Display a label<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    lbl_label1 = tk.Label(root, text = \"My text\")\n    lbl_label1.place(x=5, y=370)\n\n#Or to set label dimensions:\n    btn_button1.place(x=10, y=40, width=60, height=18)<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Setting properties<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#Background\n    lbl_label1 = tk.Label(root, text = \"My text\", bg=\"white\")\n#Border\n    borderwidth=2, relief=\"solid\"    #\"solid\", \"groove\"\n#Width\n    width=20,\n#Font\n&nbsp; &nbsp; font=('', 18, 'bold')    #'normal', 'bold', 'italic' or 'roman'\n#Text align (single line text)\n    anchor=\"center\"    #\"center\" (default), \"w\" left, \"e\" right, \"nw\" top-left, \"n\" top-center,\n#Justify (affects multiline wrapped text using \\n)\n    justify=\"left\"\n\n#Using multiple lines to make code easy to read\n    lbl_label1 = tk.Label(root,\n                       text = \"My text\",\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font=('', 18, 'bold'))    #'normal', 'bold', etc\n    lbl_label1.place(x=5, y=370)<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Update label text<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#Make it global\n    global lbl_label1\n\n    lbl_label1.configure(text = \"New text\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Multi line<\/h4>\n\n\n\n<p>Just use the \\n newline character.<br>You&#8217;ll need to set anchor and justify if you want the text aligned left (defaults to center).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Align<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>lbl_my_label = tk.Label(root, text = \"My text\", anchor=\"nw\", justify=\"left\")<\/code><\/pre>\n\n\n\n<p>anchor &#8211; Values n, ne, e, se, s, sw, w, nw, or center. For example, nw means display the information such that its top-left corner is at the top-left corner of the widget.<\/p>\n\n\n\n<p>justify &#8211; When there are multiple lines of text displayed, one of left, center, or right.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display a label Setting properties Update label text Multi line Just use the \\n newline character.You&#8217;ll need to set anchor and justify if you want the text aligned left (defaults to center). Align anchor &#8211; Values n, ne, e, se, s, sw, w, nw, or center. For example, nw means display the information such that [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[],"class_list":["post-4709","post","type-post","status-publish","format-standard","hentry","category-gui-objects"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4709"}],"version-history":[{"count":17,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4709\/revisions"}],"predecessor-version":[{"id":4962,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4709\/revisions\/4962"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}