Python GUI Programming
Introduction
Python offers multiple options for developing?Python GUI (Graphical User Interface) programming. Out of all the Python GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python?GUI with tkinter is the fastest and easiest way to create GUI applications.
There are many Python GUI Programming toolkits to start out with. Python has loads of frameworks for developing GUIs and we have gathered some of the most popular?Python GUI programming frameworks?in our list that are listed below;
Tkinter
Tkinter, a Python wrapper for Tcl/Tk, comes bundled with Python and delivers a cross-platform GUI.?it’s?a comparatively?simple?to find out?yet powerful toolkit?that gives?what appears to be a modest set of widgets. However, because the Tkinter widgets are extensible, many compound widgets?could also be?created rather easily (e.g. combo-box, scrolled panes). Due?to?its maturity and extensive documentation, Tkinter has been designated?because the?de facto?GUI for Python.?To?make?a really?simple Tkinter?framework?one only needs?the subsequent?lines of code:
import Tkinter
root = Tkinter.Tk()
root.mainloop()
From an object-oriented view one may do the following:
import Tkinter
class App:
? ? ?def __init__(self, master):
? ? ? ? ?button = Tkinter.Button(master, text="I'm a Button.")
? ? ? ? ?button.pack()
if __name__ == '__main__':
? ?root = Tkinter.Tk()
? ?app = App(root)
? ?root.mainloop()
PyGTK
PyGTK provides a convenient wrapper for the GTK library?to be used?in PythonGUI programs, taking care?of many?of the boring details?like?managing memory?and sort?casting. The bare GTK and toolkit run on Linux, Windows, and Mac OS X, but the more extensive features — when combined with PyORBit and gnome-python — require a GNOME 5 install?and maybe?wont to?write full-featured GNOME applications.
PyQt
PyQt?may be a?wrapper?around the?cross-platform Qt C++ toolkit 7 .?it’s?many widgets and
support classes 8 supporting SQL, OpenGL, SVG, XML, and advanced graphics capabilities.
A PyQt hello world example:
领英推荐
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class App(QApplication):
? ? ? def __init__(self, argv):
? ? ? ? ? super(App, self).__init__(argv)
? ? ? ? ? self.msg = QLabel("Hello, World!")
? ? ? ? ? self.msg.show()
if __name__ == "__main__":
? ? import sys
? ? app = App(sys.argv)
? ? sys.exit(app.exec_())
PyQt?may be a?set of bindings for the cross-platform Qt 10 application framework. PyQt v4?helps Qt4 and PyQt v3 supports Qt3 and earlier.
wxPython
Bindings for the cross-platform toolkit wxWidgets 11. WxWidgets?is out there?on Windows, Macintosh, and Unix/Linux.
import wx
class test(wx. App):
? ? def __init__(self):
? ? ? ? ? wx.App.__init__(self, redirect=False)
def OnInit(self):
? ? frame = wx.Frame(None, -1,
? ? ? ? ? ? ? ? ? ? ?"Test",
? ? ? ? ? ? ? ? ? ? ? pos=(50,50), size=(100,40),
? ? ? ? ? ? ? ? ? ? ? style=wx.DEFAULT_FRAME_STYLE)
? ? button = wx.Button(frame, -1, "Hello World!", (20, 20))
? ? self.frame = frame
? ? self.frame.Show()
? ? return True
if __name__ == '__main__':
? ? app = test()
? ? app.MainLoop()
Dabo
Dabo?may be a?full 3-tier application framework. Its UI layer wraps wxPython, and surely simplifies the syntax.
import dabo
dabo.ui.loadUI("wx")
class TestForm(dabo.ui.dForm):
? ? def afterInit(self):
? ? ? ? ? ? self.Caption = "Test"
? ? ? ? ? ? self.Position = (50, 50)
? ? ? ? ? ? self.Size = (100, 40)
? ? ? ? ? ? self.btn = dabo.ui.dButton(self, Caption="Hello World",
? ? ? ? ? ? ? ? ?OnHit=self.onButtonClick)
? ? self.Sizer.append(self.btn, halign="center", border=20)
? ? def onButtonClick(self, evt):
? ? ? ? ? ? ?dabo.ui.info("Hello World!")
if __name__ == '__main__':
? ? ? ? ?app = dabo.ui.dApp()
? ? ? ? ?app.MainFormClass = TestForm
? ? ? ? ?app.start()
pyFltk
pyFltk?may be a?Python wrapper for the FLTK 15,?a lightweight?cross-platform GUI tool Kit. It’s. It’s?very simple?to find out?and allows for compact user interfaces.?The ”Hello World” illustration in pyFltk looks like this:
from fltk import *
window = Fl_Window(100, 100, 200, 90)
button = Fl_Button(9,20,180,50)
button.label("Hello World")
window.end()
window.show()
Fl.run()
Other Toolkits
For more details visit: https://www.technologiesinindustry4.com