{"id":3797,"date":"2021-12-13T05:53:54","date_gmt":"2021-12-13T05:53:54","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3797"},"modified":"2021-12-13T05:53:55","modified_gmt":"2021-12-13T05:53:55","slug":"3c-wxwidgets-buttons-labels","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/13\/3c-wxwidgets-buttons-labels\/","title":{"rendered":"3c. wxWidgets &#8211; Buttons &#038; Labels"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>Buttons and labels are the most common controls used in GUI. Here we create a sample button and label and display them in a window. Though we can directly create these controls in wxFrame and display them, the end result will not be as expected, since the controls will fill the whole wxFrame. So we use a wxPanel as a container to display the controls. We will explore Panels in the next section.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">button.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Button: public wxFrame {\n\tpublic:\n\t  Button(const wxString&amp; title);\n\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">button.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;button.h&quot;\n\nButton::Button(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n\n        wxPanel *panel = new wxPanel(this, -1);\t\t\n\twxButton *btn = new wxButton(panel, -1, wxT(&quot;Click me&quot;), wxPoint(220,20));\n\twxStaticText *label = new wxStaticText(panel, -1, wxT(&quot;Click on the button&quot;), wxPoint(1,20));\n        btn-&gt;SetBackgroundColour(wxColour(100,100,20));\t\t\n\tCenter();\n}\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;button.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tButton *app = new Button(wxT(&quot;Buttons and Labels&quot;));\n\tapp-&gt;Show(true);\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"200\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-11-22-04.png\" alt=\"\" class=\"wp-image-3800\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-11-22-04.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-11-22-04-300x120.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW Buttons and labels are the most common controls used in GUI. Here we create a sample button and label and display them in a <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/13\/3c-wxwidgets-buttons-labels\/\" title=\"3c. wxWidgets &#8211; Buttons &#038; Labels\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-3797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3797"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3797\/revisions"}],"predecessor-version":[{"id":3801,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3797\/revisions\/3801"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}