{"id":4715,"date":"2024-10-07T15:55:16","date_gmt":"2024-10-07T14:55:16","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4715"},"modified":"2025-12-09T11:15:59","modified_gmt":"2025-12-09T11:15:59","slug":"button","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/gui\/tkinter-tk-gui-toolkit\/gui-objects\/button","title":{"rendered":"Button"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Create a button<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    btn_button1 = tk.Button(root, text = \"Button 1\", fg = \"black\", command=btn_button1_clicked)\n    btn_button1.place(x=400, y=30)\n\n#Or to set button 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>#Height\n    height=1    #You can only set as integer number of lines, use place to fine set width and height)<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Respond to a button press<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#****************************************\n#****************************************\n#*********** BUTTON 1 CLICKED ***********\n#****************************************\n#****************************************\ndef btn_button1_clicked():\n    #Do something...<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Up Down Left Right buttons example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    #Label\n    lbl_loadcell_weight = tk.Label(root, text = \"?g\",\n                                bg=\"white\", relief=\"groove\",\n                                width=8,\n                                borderwidth=2,\n                                font=('', 12, 'bold'))    #'normal', 'bold', etc)\n    lbl_loadcell_weight.place(x=0, y=30)\n\n    #Down button\n    btn_weight_value_down = tk.Button(root, text = \"\u25bc\", fg = \"black\", width=2, command=btn_weight_down_clicked)\n    btn_weight_value_down.place(x=86, y=29)\n    \n    #Up button\n    btn_weight_value_up = tk.Button(root, text = \"\u25b2\", fg = \"black\", width=2, command=btn_weight_up_clicked)\n    btn_weight_value_up.place(x=110, y=29)\n    \n    #Left button\n    btn_weight_value_left = tk.Button(root, text = \"&#x25c0;\", fg = \"black\", width=2, command=btn_weight_left_clicked)\n    btn_weight_value_left.place(x=86, y=54)\n    \n    #Right button\n    btn_weight_value_right = tk.Button(root, text = \"&#x25b6;\", fg = \"black\", width=2, command=btn_weight_right_clicked)\n    btn_weight_value_right.place(x=110, y=54)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create a button Setting properties Respond to a button press Up Down Left Right buttons example<\/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-4715","post","type-post","status-publish","format-standard","hentry","category-gui-objects"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4715","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=4715"}],"version-history":[{"count":7,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4715\/revisions"}],"predecessor-version":[{"id":4961,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4715\/revisions\/4961"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}