{"id":7939,"date":"2020-08-20T17:48:09","date_gmt":"2020-08-20T17:48:09","guid":{"rendered":"https:\/\/www.askpython.com\/?p=7939"},"modified":"2021-06-24T01:08:01","modified_gmt":"2021-06-24T01:08:01","slug":"top-best-python-gui-libraries","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/top-best-python-gui-libraries","title":{"rendered":"Top 5 Best Python GUI Libraries"},"content":{"rendered":"\n<p>In this article, we will go through the top 5 Python GUI libraries that you can use in your projects. Keep reading to find out about them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a GUI?<\/h2>\n\n\n\n<p>A GUI or a graphical user interface is an interactive environment to take responses from users on various situations such as forms, documents, tests, etc. It provides the user with a good interactive screen than a traditional Command Line Interface (CLI).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">List of Best Python GUI Libraries<\/h2>\n\n\n\n<p>Let&#8217;s get right into it and look at the top GUI Libraries for Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. PyQT5<\/h3>\n\n\n\n<p>PyQT5 is a graphical user interface (GUI) framework for Python. It is very popular among developers and the GUI can be created by coding or a QT designer. A QT Development framework is a visual framework that allows drag and drop of widgets to build user interfaces.<\/p>\n\n\n\n<p>It is a free, open source binding software and is implemented for cross platform application development framework. It is used on Windows, Mac, Android, Linux and Raspberry PI.<\/p>\n\n\n\n<p>For the installation of PyQT5 , you can use the following command :<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install pyqt5\n<\/pre><\/div>\n\n\n<p>A simple code is demonstrated here:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom PyQt5.QtWidgets import QApplication, QMainWindow\nimport sys\n\nclass Window(QMainWindow):\n   def __init__(self):\n       super().__init__()\n\n       self.setGeometry(300, 300, 600, 400)\n       self.setWindowTitle(&quot;PyQt5 window&quot;)\n       self.show()\n\napp = QApplication(sys.argv)\nwindow = Window()\nsys.exit(app.exec_())\n\n<\/pre><\/div>\n\n\n<p>The output of the above code is as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/PyQt5.png\" alt=\"PyQt5\" class=\"wp-image-7942\" width=\"378\" height=\"315\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/PyQt5.png 452w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/PyQt5-300x250.png 300w\" sizes=\"auto, (max-width: 378px) 100vw, 378px\" \/><figcaption>PyQt5<\/figcaption><\/figure><\/div>\n\n\n\n<p><em>ScienceSoft\u2019s team of\u00a0<\/em><a rel=\"noreferrer noopener\" class=\"rank-math-link\" href=\"https:\/\/www.scnsoft.com\/services\/hire-python-developers\" target=\"_blank\"><em>Python developers<\/em><\/a><em>\u00a0highlights the benefits of using PyQt:<\/em><\/p>\n\n\n\n<p><strong>PyQt is a mature set of Python bindings to Qt for cross-platform development of desktop apps. It offers a rich selection of built-in widgets and tools for custom widgets creation to shape sophisticated GUIs, as well as robust SQL database support to connect to and interact with databases.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Python Tkinter<\/h3>\n\n\n\n<p>Another GUI framework is called <a href=\"https:\/\/www.askpython.com\/tkinter\" class=\"rank-math-link\">Tkinter<\/a>. Tkinter is one of the most popular Python GUI libraries for developing desktop applications. It\u2019s a combination of the TK and python standard GUI framework. <\/p>\n\n\n\n<p>Tkinter provides diverse widgets such as <a href=\"https:\/\/www.askpython.com\/python-modules\/tkinter\/tkinter-frame-and-label\" class=\"rank-math-link\">labels<\/a>, <a href=\"https:\/\/www.askpython.com\/python-modules\/tkinter\/tkinter-buttons\" class=\"rank-math-link\">buttons<\/a>, text boxes, <a href=\"https:\/\/www.askpython.com\/python-modules\/tkinter\/tkinter-checkbox-and-checkbutton\" class=\"rank-math-link\">checkboxes <\/a>that are used in a graphical user interface application. <\/p>\n\n\n\n<p>The button control widgets are used to display and develop applications while the <a href=\"https:\/\/www.askpython.com\/python-modules\/tkinter\/tkinter-canvas\" class=\"rank-math-link\">canvas widget<\/a> is used to draw shapes like lines, polygons, rectangles, etc. in the application. Furthermore, Tkinter is a <a href=\"https:\/\/www.askpython.com\/built-in-methods\" class=\"rank-math-link\">built-in<\/a> library for Python, so you don&#8217;t need to install it like other GUI framework. Given below is an example of coding using Tkinter.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom tkinter import *\n\nclass Root(Tk):\n    def __init__(self):\n        super(Root,self).__init__()\n\n        self.title(&quot;Python Tkinter&quot;)\n        self.minsize(500,400)\n\nroot = Root()\nroot.mainloop()\n<\/pre><\/div>\n\n\n<p>The output of the above code is as shown below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Tkinter.png\" alt=\"Tkinter\" class=\"wp-image-7943\" width=\"342\" height=\"288\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Tkinter.png 456w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Tkinter-300x253.png 300w\" sizes=\"auto, (max-width: 342px) 100vw, 342px\" \/><figcaption>Tkinter<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3. PySide 2<\/h3>\n\n\n\n<p>The third Python GUI libraries that we are going to talk about is PySide2 or you can call it QT for python. Qt for Python offers the official Python bindings for Qt (PySide2), enabling the use of its APIs in Python applications, and a binding generator tool (Shiboken2) which can be used to expose C++ projects into Python. <\/p>\n\n\n\n<p>Qt for Python is available under the LGPLv3\/GPLv3 and the Qt commercial license.<\/p>\n\n\n\n<p>So now let me show you the installation process and also an example. So for the installation, you can just simply use:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install PySide2\n<\/pre><\/div>\n\n\n<p>Here, is an example to set up GUI frame using PySide2.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom PySide2.QtWidgets import QtWidgets, QApplication\nimport sys\n\nclass Window(QtWidgets):\n    def __init__(self):\n        super().__init__()\n\n        self.setWindowTitle(&quot;Pyside2 Window&quot;)\n        self.setGeometry(300,300,500,400)\n\n\napp = QApplication(sys.argv)\nwindow=Window()\nwindow.show()\napp.exec_()\n<\/pre><\/div>\n\n\n<p>The output of the above code is as shown below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Pyside2.png\" alt=\"Pyside2\" class=\"wp-image-7944\" width=\"368\" height=\"308\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Pyside2.png 452w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Pyside2-300x251.png 300w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" \/><figcaption>Pyside2<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">4. Kivy<\/h3>\n\n\n\n<p>Another GUI framework that we are going to talk about is called Kivy. Kivy is an Open source Python library for the rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. <\/p>\n\n\n\n<p>Kivy runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi. You can run the same code on all supported platforms. It can natively use most inputs, protocols and devices including WM_Touch, WM_Pen, Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID. <\/p>\n\n\n\n<p>Kivy is 100% free to use, under an MIT license.<\/p>\n\n\n\n<p>The toolkit is professionally developed, backed, and used. You can use it in a commercial product. The framework is stable and has a well-documented API, plus a programming guide to help you get started.<\/p>\n\n\n\n<p>The graphics engine of Kivy is built over OpenGL ES 2, using a modern and fast graphics pipeline.<\/p>\n\n\n\n<p>The toolkit comes with more than 20 widgets, all highly extensible. Many parts are written in C using Cython, and tested with regression tests.<\/p>\n\n\n\n<p>Coming to the installation of Kivy, you need to install the dependency \u201cglew\u201d. You can use the <a href=\"https:\/\/www.askpython.com\/python-modules\/python-pip\" class=\"rank-math-link\">pip command<\/a> as below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew\n<\/pre><\/div>\n\n\n<p>Enter this command and hit enter, it will be installed. After that you need to type this command to install Kivy:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install Kivy\n<\/pre><\/div>\n\n\n<p>So after installation, let me show you a simple example of Kivy to show how easy it is.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom kivy.app import App\nfrom kivy.uix.button import Button\n\nclass TestApp(App):\n    def build(self):\n        return Button(text= &quot; Hello Kivy World &quot;)\n\nTestApp().run()\n<\/pre><\/div>\n\n\n<p>The output of the above code is as shown below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Kivy.png\" alt=\"Kivy\" class=\"wp-image-7945\" width=\"410\" height=\"316\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Kivy.png 717w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/Kivy-300x231.png 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><figcaption>Kivy<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">5. wxPython<\/h3>\n\n\n\n<p>So the last GUI framework that we are going to talk about is wxPython. wxPython is a cross-platform GUI toolkit for the Python programming language. <\/p>\n\n\n\n<p>It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a set of Python extension modules that wrap the GUI components of the popular wxWidgets cross-platform library, which is written in C++.<\/p>\n\n\n\n<p>Like Python and wxWidgets, wxPython is Open Source. <\/p>\n\n\n\n<p>wxPython is a cross-platform toolkit. This means that the same program will run on multiple platforms without modification. Currently,  the Supported platforms are Microsoft Windows, Mac OS X and macOS, and Linux.<\/p>\n\n\n\n<p>Now I&#8217;m going to show you the installation process and create a simple example. So for the installation just type the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install wxPython\n<\/pre><\/div>\n\n\n<p>Here is an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport wx\n\nclass MyFrame(wx.Frame):\n    def __init__(self,parent,title):\n        super(MyFrame,self).__init__(parent,title=title,size=(400,300))\n\n\n    self.panel=MyPanel(self)\n\n\nclass MyPanel(wx.Panel):\n    def __init__(self,parent):\n        super(MyPanel,self).__init__(parent)\n\n\nclass MyApp(wx.App):\n    def OnInit(self):\n        self.frame=MyFrame(parent=None, title= &quot;wxPython Window&quot;)\n        self.frame.show()\n        return True\n\napp = MyApp()\napp.MainLoop()\n<\/pre><\/div>\n\n\n<p>The output of the above code is as shown below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"352\" height=\"262\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/wxPython.png\" alt=\"WxPython\" class=\"wp-image-7946\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/wxPython.png 352w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/wxPython-300x223.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/08\/wxPython-160x120.png 160w\" sizes=\"auto, (max-width: 352px) 100vw, 352px\" \/><figcaption>WxPython<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>So now we have seen 5 Python GUI libraries and in my opinion, PySide2 and pyQt5 are the more powerful GUI frameworks. But they do come with a commercial license and that explains why they&#8217;re feature-rich. Tkinter, Kivy, and wxPython are the free GUI libraries for Python.<\/p>\n\n\n\n<p>What&#8217;s your favorite GUI library in Python?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will go through the top 5 Python GUI libraries that you can use in your projects. Keep reading to find out about them. What is a GUI? A GUI or a graphical user interface is an interactive environment to take responses from users on various situations such as forms, documents, tests, [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":7949,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-modules"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/7939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=7939"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/7939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/7949"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=7939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=7939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=7939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}