{"id":9948,"date":"2019-03-27T07:58:34","date_gmt":"2019-03-27T07:58:34","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=9948"},"modified":"2023-11-17T07:04:17","modified_gmt":"2023-11-17T07:04:17","slug":"look-at-this-python-gui-example","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/look-at-this-python-gui-example\/","title":{"rendered":"Look at This Python GUI Example"},"content":{"rendered":"<blockquote><p><em>One attractive feature of Python is the simplicity, speed, and flexibility in creating applications with a graphical user interface (GUI). This advantage is associated not only with a large number of supported graphic libraries: Tkinter, PyQt, PyGTK, wxPython, Pygames, etc. The main reason is the interpretive nature of the Python platform; because of the availability of Python code, the appearance of the graphical application can always be changed or supplemented. And the entire interface from the Python code to the actual implementation of the GUI is hidden inside the Python library modules. Check out our Python GUI example to know about more advantages of developing GUI applications in <a href=\"https:\/\/softwaredevelopersforhire.com\/python\/\" target=\"_blank\" rel=\"noopener nofollow\">Python<\/a>.<\/em><\/p>\n<p><em>The Python GUI sample presented below was developed by an expert in programming. You will complete your own task much faster if you read through our example and get some ideas from it. Because of the ease of demonstrating the problem and its solution, any student can understand the example. Or you can ask for <a href=\"https:\/\/assignmentshark.com\/\" target=\"_blank\" rel=\"noopener\">assignment help online<\/a> and rest assured in the results.<\/em><\/p>\n<p><em> The sample is available for you now, so enjoy reading!<\/em><!--more--><\/p><\/blockquote>\n<h2>Python GUI Task Example<\/h2>\n<p>When starting programming in Python and having output in the console, everything is easy and pretty much the same as in any programming language. This is the moment when Graphical User Interface comes into play. It is more interesting to build applications when they have an appropriate interface.<\/p>\n<p>So this guide will discuss how to add GUI to the application in Python using the standard GUI library Tkinter.<\/p>\n<p>The basic code shown below creates an empty window.<\/p>\n<p>from\u200b tkinter \u200bimport\u200b *<\/p>\n<p>top = Tk()<\/p>\n<p>top.mainloop()<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/1-3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9950 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/1-3.jpg\" alt=\"python gui example\" width=\"216\" height=\"238\" \/><\/a><\/p>\n<p>Generally, Tkinter library consists of multiple widgets of various types that together with available functions and methods allow the desired graphical user interface to be developed. So, let\u2019s add a label and button to the window.<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/2-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9952 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/2-7.png\" alt=\"python gui sample\" width=\"995\" height=\"531\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/2-7.png 995w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/2-7-300x160.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/2-7-768x410.png 768w\" sizes=\"auto, (max-width: 995px) 100vw, 995px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/3-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9954 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/3-4.png\" alt=\"python gui application example\" width=\"132\" height=\"85\" \/><\/a><\/p>\n<p>The code shown above lets the button \u2018Hello!\u2019 close the window when it is clicked. The structure of code has changed because class has better implementation and organization.<\/p>\n<p>Besides various widgets, Tkinter contains different methods of organizing the layout for those elements. So, there are three classes: grid, pack, and place. Grid is the geometry of a two-dimensional grid layout. Pack manager allows to create a layout by packing different elements as blocks. Previous examples used pack method to form the layout of widgets. Place geometry provides the ability to locate elements at a specific position. The most widely used is grid. So, the next example shows its usage.<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/4-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9956 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/4-3.png\" alt=\"python gui example code\" width=\"985\" height=\"433\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/4-3.png 985w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/4-3-300x132.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/4-3-768x338.png 768w\" sizes=\"auto, (max-width: 985px) 100vw, 985px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/6-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9958 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/6-1.jpg\" alt=\"python gui example code explained\" width=\"472\" height=\"110\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/6-1.jpg 472w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/6-1-300x70.jpg 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/a><\/p>\n<p>Place method requires you to define the location of any element in the window. So, let\u2019s look at how the window above can be created using place function.<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/7-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9960 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/7-3.png\" alt=\"simple python gui example\" width=\"931\" height=\"368\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/7-3.png 931w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/7-3-300x119.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/7-3-768x304.png 768w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/a><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/8-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9962 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/8-3.png\" alt=\"python gui tkinter example\" width=\"466\" height=\"118\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/8-3.png 466w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/8-3-300x76.png 300w\" sizes=\"auto, (max-width: 466px) 100vw, 466px\" \/><\/a><\/p>\n<p>As you can see, the window size is also necessary to define. So, this method requires more actions to be performed manually.<\/p>\n<p>Different layout managers have been discussed, so now is the time for adding functionality to different widgets.<\/p>\n<p>The program below outputs entered string to the console after clicking the button \u2018Get\u2019. Also, the button here has the property relief set to RIDGE, which changes the form of the button.<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/9-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9964 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/9-3.png\" alt=\"python gui tkinter example completed\" width=\"877\" height=\"592\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/9-3.png 877w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/9-3-300x203.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/9-3-768x518.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/a><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/10-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9966 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/10-1.jpg\" alt=\"python gui tkinter example in details\" width=\"513\" height=\"263\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/10-1.jpg 513w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/10-1-300x154.jpg 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><\/p>\n<p>Since this is the basic tutorial of GUI in Python, no huge program is implemented here. Let\u2019s implement the menu with several tabs showing different information upon clicking various options as a final small program.<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9968 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/11.png\" alt=\"python gui tkinter example explained in details\" width=\"593\" height=\"237\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/11.png 593w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/11-300x120.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/a><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9970 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/12.png\" alt=\"python simple gui example\" width=\"779\" height=\"346\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/12.png 779w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/12-300x133.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/12-768x341.png 768w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/a><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9972 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1.png\" alt=\"python simple gui example analyzed\" width=\"1200\" height=\"742\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1.png 1200w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1-300x186.png 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1-768x475.png 768w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/13-1-1024x633.png 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9974 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14.jpg\" alt=\"python gui example code tkinter\" width=\"1250\" height=\"583\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14.jpg 1250w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14-300x140.jpg 300w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14-768x358.jpg 768w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/14-1024x478.jpg 1024w\" sizes=\"auto, (max-width: 1250px) 100vw, 1250px\" \/><\/a><\/p>\n<p>Console output:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/15.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9976 size-full\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2018\/08\/15.jpg\" alt=\"python gui example code tkinter analyzed\" width=\"251\" height=\"52\" \/><\/a><\/p>\n<p>As you can see, the menu tab has a sub menu in itself, and when clicking on any option the corresponding output appears in the console. Also, the status bar at the bottom of the window simply shows the approximate status of the program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One attractive feature of Python is the simplicity, speed, and flexibility in creating applications with a graphical user interface (GUI). This advantage is associated not only with a large number of supported graphic libraries: Tkinter, PyQt, PyGTK, wxPython, Pygames, etc. The main reason is the interpretive nature of the Python platform; because of the availability [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-9948","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/9948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=9948"}],"version-history":[{"count":4,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions"}],"predecessor-version":[{"id":13588,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions\/13588"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=9948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=9948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=9948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}