SlideShare a Scribd company logo
| 1P a g e
wxFormBuilder - Tutorial on “A
GUI for making GUIs” for Python
By
Website: www.UmarYusuf.com/wxpy
Email: umaryusuf49@gmail.com
Graphical User Interfaces (GUIs) in Python are commonly created
using Tk via the Tkinter package. However, at the moment of
writing this post, designing GUI via the Tkinter package is done
purely in code (python syntax) which means that a simple dialog
window may consist of approximately 100+ lines of code.
| 2P a g e
Wouldn‟t it be pleasant if we had a visual tool for making GUIs?
That is “A GUI for making GUIs”. Creating GUI with code
(WxPython) is too tedious work and it requires lots of attention
and time. With WXFormBuilder, you create GUI much faster and
efficiently in less time. In most cases this is faster than writing
this code by hand.
That is what „wxFormBuilder‟ is set to realize. WxFormBuilder is a
Rapid Application Development (RAD) tool for wxWidgets GUI
design. It is an open source GUI designer application for
wxWidgets toolkit, which allows creating cross-platform
applications.
WxFormBuilder allows you to design your GUIs visually and save
them in a wxFormBuilder Project File - *.fbp file (which is just an
XML file listing every component in your GUI and defining each
component‟s properties). Then, the *.fbp file can be converted
automatically into a Python *.py file ready to be imported into
your Python program. It also serves as Source code generation
| 3P a g e
other programming languages are supported such as: C++, PHP,
Lua and XRC.
| 4P a g e
Tutorial objective:
I will guide you through the basics of wxFormBuilder as used with
wxPython generated code. The goal is for you to build a usable
First GUI in Python.
We are going to create a little application that will take selected
text from the user “choice box” and append/print the chosen text
to a static text box that has “Hello…” on it.
The end result will be a GUI (as sketched below) that just
outputs: Hello… World, or Hello… Africa, or Hello… Asia, or Hello…
Europe, or Hello… America - on the displayed static text box.
| 5P a g e
| 6P a g e
Prerequisites:
We need to have the following packages installed:-
~ Python 2.7
~ wxpython 3.0.2.0
~ wxformbuilder 3.5-RC1
~ Pyinstaller to freeze the application (create an .exe on Windows
or a .app on osx)
~ Text editor (Sublime Text, Notepad++, Pycharm or anything
similar).
Combination of any versions will do as long as they are
compatible with each other. I used Python 2.7.10 Anaconda 2.3.0
(64-bit), wxPython 3.0.2.0 (msw-unicode), wxFormBuilder 3.5-
RC1 (unicode) and Sublime Text 3.
The prerequisite packages most be installed as above in the order
mentioned and we should be good to go.
| 7P a g e
Building the GUI
Start wxformbuilder, by default a new project is already opened.
Save the new project to your desired directory/folder location on
your PC with any name (I used: MyProject.fbp).
Set file name to „gui‟ (or whatever name you want) and set code
generation to „Python‟ (since we want our GUI to be in
wxPython).
Add a frame from the “Form” tab.
Rename the frame name to "MainFrame" on the Object properties
panel. This is optional, but for larger applications it will be
necessary to differentiate between frames by their names.
| 8P a g e
Add a wxBoxSizer from the “Layout” tab.
Set “orient” to wxVERTICAL. This will hold our GUI components
and stack them vertically
| 9P a g e
Add a static text (wxSTATICTEXT) from the “Common” tab:
From the tool bar, set the static text to “Expand” and “Align
Center Horizontally”.
From the Object properties panel, set the following properties;
Name = HelloText
Style = wxALIGN_CENTRE
Label = Hello...
Font Point Size = 20
| 10P a g e
Add a drop down box (wxCHOICE) from the “Common” tab:
From the tool bar, set the drop down box to “Expand” and “Align
Center Horizontally”.
From the Object properties panel, set the following properties;
Name = choice
Choices = World, Africa, America, Asia, Europ
Font Point Size = 20
| 11P a g e
Add a button (wxBUTTON) from the “Common” tab:
From the tool bar, set the drop down box to “Expand” and “Align
Center Horizontally”.
From the Object properties panel, set the following properties;
Name = button
Label = Print
Font Point Size = 20
Bind an event for button clicks since we want to take selected
text from the user and append/print the chosen text to a static
text box above when the user clicks the button:
From the Object properties panel, select “Events” tab and set the
OnButtonClick event to “printFunc” (o whatever name you want,
| 12P a g e
but be sure to remember the name as it is the method/function
name that will control the button)
Save the wxformbuilder project to your project folder. Then click
Generate code from the menu/tool bar or press F8 button on your
keyboard.
| 13P a g e
The content of your project folder should contain the
wxformbuilder project file and the generated file. You should end
up with a file called “gui.py” in the directory you saved in. This
file holds the code for generating the graphics.
Run the generated code “gui.py” as follow:-
Open the generated file “gui.py” in a text editor (I used sublime
text editor)
Scroll to the bottom and add the code below;-
app = wx.App()
frame = MainFrame(None).Show()
app.MainLoop()
Above is mandatory in wxPython to create an application. It
creates an object of MainFrame class and shows/displays it and
starts the application on an infinite loop.
| 14P a g e
Now try running (Ctrl+B for Sublime text) the code and you
should see something like this:
| 15P a g e
Now let‟s modify it to do something when user clicks the “Print”
button. Recall that we bind an OnButtonClick event for the button
named “printFunc” method/function.
Edit the “printFunc” method/function to look like below;-
def printFunc( self, event ):
hw = self.choice.GetStringSelection()
self.HelloText.SetLabel('Hello... ' + hw)
self.Layout()
The method/function gets the selected text and stores it in a
variable “hw”, then appends it to the static text label. The layout
is retained by calling the layout method/function.
Recall the “choice” and “HelloText” are names of the “drop down
box” and “static text” respectively as created earlier.
| 16P a g e
Building an executable:
Now we want to share the application with user who may not
have python install on their computers. So we need a way to
make our app to run on any computer without python installed on
it. This process is generally referred to as "Freezing our Code".
The advantage of distributing this way is that your application will
work even if the user doesn‟t already have the required version of
Python installed. On Windows, and even on many Linux
distributions and OSX versions, the right version of Python will
not already be installed.
One disadvantage is that it will bloat your distribution by about
2MB. Another problem is that your application will not receive any
security updates to the version of Python it uses unless you
freeze a new version and get users to download it.
There are multiple tools to do this as compared in the table
below, showing the Solutions and platforms/features supported:
http://docs.python-guide.org/en/latest/shipping/freezing/
Solution Windows Linux
OS
X
Python
3
License
One-
file
mode
Zipfile
import
Eggs
pkg_resources
support
bbFreeze yes yes yes no MIT no yes yes yes
py2exe yes no no yes MIT yes yes no no
pyInstaller yes yes yes yes GPL yes no yes no
cx_Freeze yes yes yes yes PSF no yes yes no
py2app no no yes yes MIT no yes yes yes
| 17P a g e
Installing PyInstaller
1- Run the following commands
pip install pyinstaller
Or
python.exe -m pip install pyinstaller
2- Download the PyInstaller package from and run this
command from the extracted package directory
python setup.py install
Building the Executable:
From our application folder (directory), open cmd and run the
command below;-
pyinstaller.exe --onefile --windowed gui.py
| 18P a g e
| 19P a g e
It‟s that easy.
If the build was successful, the final executable, gui.exe, and any
associated files, will be placed in the dist directory, which will be
created if it doesn‟t exist.
Let me briefly describe the options that are being used:
 --onefile is used to package everything into a single
executable. If you do not specify this option, the libraries,
etc. will be distributed as separate files alongside the main
executable.
 --windowed prevents a console window from being displayed
when the application is run. If you‟re releasing a non-
| 20P a g e
graphical application (i.e. a console application), you do not
need to use this option.
 gui.py the main source file of the application. The base
name of this script will be used to name of the executable,
however you may specify an alternative executable name
using the --name option.
Check the PyInstaller Manual for more configuration information.
After the build, a gui.spec file will be created. This file contains all
of the options used to run PyInstaller, and can be fed back into
PyInstaller for future builds in place of the command line options,
if desired.
To add icon and version text to the exe file, use command below
(version.txt will be provided, see the manual);-
pyinstaller.exe --onefile --windowed --
icon=srcimgfavicon.ico --version-file=version.txt gui.py
Building the Installer:
PyInstaller merely assembles the files needed to run your python
program; it is not an installer builder. An installer will further
compress the app size.
There are plenty of good installer builders out there including
some that are open source e.g.: NSIS and Inno Setup.
| 21P a g e
Download the code:
The files generated throughout the tutorial can be downloaded
from the link below. Size is 25mb
https://www.dropbox.com/s/w2e6g7mercdqly0/HelloGUI.zip?dl=
0
| 22P a g e
Exercise:
As an exercise;
1- Add an icon and a title to the title bar?
2- Set a color to the frame‟s background?
3- Add two buttons to exit and reset the app?
4- Finally, add menus to handle the button tasks and to provide
help for the app?
See final result to the exercise in image below.
Solution to this and more are available in video format on this
link: www.UmarYusuf.com/wxpy
| 23P a g e
Good luck, have fun, and I hope my tutorial was useful to you?
Thanks for reading!
Email: umaryusuf49@gmail.com
Website: www.UmarYusuf.com
| 24P a g e
Referenced Materials
Other tutorials that motivated this post
1- Ultra Quick GUIs with Wxformbuilder/Python by Vighnesh
Birodkar
https://www.facebook.com/vighnesh.birodkar
https://vcansimplify.wordpress.com/2013/04/08/ultra-
quick-guis-with-wxformbuilderpython/
2- Rapidly building a python GUI application by Sebastian
Nilsson
http://sebastiannilsson.com/en/blogg/rapidly-building-
python-gui-application/
3- How to Install PyQt5 and Build Your First GUI in Python 3.4
http://projects.skylogic.ca/blog/how-to-install-pyqt5-and-
build-your-first-gui-in-python-3-4/
4- Tutorial: Creating GUI Applications in Python with QT by
Alex Fedosov
http://www.cs.usfca.edu/~afedosov/qttut/
5- Creating an Executable from a Python Script by Matt
Borgerson
https://mborgerson.com/creating-an-executable-from-a-
python-script
Ad

More Related Content

What's hot (20)

Hướng dẫn tự học Linux
Hướng dẫn tự học LinuxHướng dẫn tự học Linux
Hướng dẫn tự học Linux
Nguyễn Duy Nhân
 
Hangman
HangmanHangman
Hangman
pattaranattamon
 
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
nataliej4
 
.NET Oxford Windows Subsystem for Linux v2
.NET Oxford Windows Subsystem for Linux v2.NET Oxford Windows Subsystem for Linux v2
.NET Oxford Windows Subsystem for Linux v2
Stuart Leeks
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
Mazenetsolution
 
Đề tài: Hệ thống giám sát mạng dựa trên phần mềm nguồn mở, HAY
Đề tài: Hệ thống giám sát mạng dựa trên phần mềm nguồn mở, HAYĐề tài: Hệ thống giám sát mạng dựa trên phần mềm nguồn mở, HAY
Đề tài: Hệ thống giám sát mạng dựa trên phần mềm nguồn mở, HAY
Dịch vụ viết bài trọn gói ZALO 0917193864
 
Giáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTITGiáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTIT
NguynMinh294
 
thuật toán c45
thuật toán c45thuật toán c45
thuật toán c45
duy10882002
 
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂYLUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
ssuserc1c2711
 
Bài tập thực hành C#
Bài tập thực hành C#Bài tập thực hành C#
Bài tập thực hành C#
Dân Chơi Khu Phố
 
BKK16-205 RDK-B IoT
BKK16-205 RDK-B IoTBKK16-205 RDK-B IoT
BKK16-205 RDK-B IoT
Linaro
 
Extending GDB with Python
Extending GDB with PythonExtending GDB with Python
Extending GDB with Python
Lisa Roach
 
Bao cao da lap trinh manh
Bao cao da lap trinh manhBao cao da lap trinh manh
Bao cao da lap trinh manh
Bồ Công Anh
 
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
TiLiu5
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
Igalia
 
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vnLập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
tailieumienphi
 
Ipsec vpn v0.1
Ipsec vpn v0.1Ipsec vpn v0.1
Ipsec vpn v0.1
Sankaranarayanan Subramanian
 
Hướng dẫn viết báo cáo chuẩn - HUST
Hướng dẫn viết báo cáo chuẩn - HUSTHướng dẫn viết báo cáo chuẩn - HUST
Hướng dẫn viết báo cáo chuẩn - HUST
The Nguyen Manh
 
đề Tài mã hóa md5
đề Tài mã hóa md5đề Tài mã hóa md5
đề Tài mã hóa md5
Vcoi Vit
 
Hướng dẫn tự học Linux
Hướng dẫn tự học LinuxHướng dẫn tự học Linux
Hướng dẫn tự học Linux
Nguyễn Duy Nhân
 
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
Triền khai firewall thế hệ mới bảo vệ hệ thống mạng doanh nghiệp 9314760
nataliej4
 
.NET Oxford Windows Subsystem for Linux v2
.NET Oxford Windows Subsystem for Linux v2.NET Oxford Windows Subsystem for Linux v2
.NET Oxford Windows Subsystem for Linux v2
Stuart Leeks
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
Mazenetsolution
 
Giáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTITGiáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTIT
NguynMinh294
 
thuật toán c45
thuật toán c45thuật toán c45
thuật toán c45
duy10882002
 
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂYLUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
LUẬN VĂN THẠC SĨ: ỨNG DỤNG HỌC SÂU TRONG PHÂN LOẠI TRÁI CÂY
ssuserc1c2711
 
BKK16-205 RDK-B IoT
BKK16-205 RDK-B IoTBKK16-205 RDK-B IoT
BKK16-205 RDK-B IoT
Linaro
 
Extending GDB with Python
Extending GDB with PythonExtending GDB with Python
Extending GDB with Python
Lisa Roach
 
Bao cao da lap trinh manh
Bao cao da lap trinh manhBao cao da lap trinh manh
Bao cao da lap trinh manh
Bồ Công Anh
 
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
BÀI GIẢNG THIẾT KẾ, XÂY DỰNG MẠNG_10433312092019
TiLiu5
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
Igalia
 
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vnLập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
tailieumienphi
 
Hướng dẫn viết báo cáo chuẩn - HUST
Hướng dẫn viết báo cáo chuẩn - HUSTHướng dẫn viết báo cáo chuẩn - HUST
Hướng dẫn viết báo cáo chuẩn - HUST
The Nguyen Manh
 
đề Tài mã hóa md5
đề Tài mã hóa md5đề Tài mã hóa md5
đề Tài mã hóa md5
Vcoi Vit
 

Similar to wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python (20)

DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
Umar Yusuf
 
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
Umar Yusuf
 
PyQt.pptx
PyQt.pptxPyQt.pptx
PyQt.pptx
manishgupta316325
 
Using Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentUsing Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) Environment
Mahmoud Samir Fayed
 
Impl installation manual
Impl installation manualImpl installation manual
Impl installation manual
Alkis Vazacopoulos
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
Tech Bikram
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
Celine George
 
Software Instructions
Software InstructionsSoftware Instructions
Software Instructions
Anastasia Khudoyarova
 
Getting started with wxWidgets
Getting started with wxWidgets Getting started with wxWidgets
Getting started with wxWidgets
Iulian-Nicu Şerbănoiu
 
Prg 218 entire course
Prg 218 entire coursePrg 218 entire course
Prg 218 entire course
grades4u
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Prabindh Sundareson
 
Compile open cpn on windows
Compile open cpn on windowsCompile open cpn on windows
Compile open cpn on windows
randikaucsc
 
Getting started with_graphics
Getting started with_graphicsGetting started with_graphics
Getting started with_graphics
PyayNA
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntu
kesavan N B
 
InstallationGuide.pdf
InstallationGuide.pdfInstallationGuide.pdf
InstallationGuide.pdf
sahirzakaria
 
How to Install Odoo 18 with Pycharm - Odoo 18 Slides
How to Install Odoo 18 with Pycharm - Odoo 18 SlidesHow to Install Odoo 18 with Pycharm - Odoo 18 Slides
How to Install Odoo 18 with Pycharm - Odoo 18 Slides
Celine George
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01
Getachew Ganfur
 
C++ for hackers
C++ for hackersC++ for hackers
C++ for hackers
Franciny Salles
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdf
MuzamilFaiz
 
Fltk tutorial
Fltk tutorialFltk tutorial
Fltk tutorial
Brijesh Naik
 
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
Umar Yusuf
 
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!DESKTOP GUI APP DEVELOPMENT USING PYTHON!
DESKTOP GUI APP DEVELOPMENT USING PYTHON!
Umar Yusuf
 
Using Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentUsing Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) Environment
Mahmoud Samir Fayed
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
Tech Bikram
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
Celine George
 
Prg 218 entire course
Prg 218 entire coursePrg 218 entire course
Prg 218 entire course
grades4u
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Prabindh Sundareson
 
Compile open cpn on windows
Compile open cpn on windowsCompile open cpn on windows
Compile open cpn on windows
randikaucsc
 
Getting started with_graphics
Getting started with_graphicsGetting started with_graphics
Getting started with_graphics
PyayNA
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntu
kesavan N B
 
InstallationGuide.pdf
InstallationGuide.pdfInstallationGuide.pdf
InstallationGuide.pdf
sahirzakaria
 
How to Install Odoo 18 with Pycharm - Odoo 18 Slides
How to Install Odoo 18 with Pycharm - Odoo 18 SlidesHow to Install Odoo 18 with Pycharm - Odoo 18 Slides
How to Install Odoo 18 with Pycharm - Odoo 18 Slides
Celine George
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01
Getachew Ganfur
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdf
MuzamilFaiz
 
Ad

Recently uploaded (20)

Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Ad

wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python

  • 1. | 1P a g e wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python By Website: www.UmarYusuf.com/wxpy Email: [email protected] Graphical User Interfaces (GUIs) in Python are commonly created using Tk via the Tkinter package. However, at the moment of writing this post, designing GUI via the Tkinter package is done purely in code (python syntax) which means that a simple dialog window may consist of approximately 100+ lines of code.
  • 2. | 2P a g e Wouldn‟t it be pleasant if we had a visual tool for making GUIs? That is “A GUI for making GUIs”. Creating GUI with code (WxPython) is too tedious work and it requires lots of attention and time. With WXFormBuilder, you create GUI much faster and efficiently in less time. In most cases this is faster than writing this code by hand. That is what „wxFormBuilder‟ is set to realize. WxFormBuilder is a Rapid Application Development (RAD) tool for wxWidgets GUI design. It is an open source GUI designer application for wxWidgets toolkit, which allows creating cross-platform applications. WxFormBuilder allows you to design your GUIs visually and save them in a wxFormBuilder Project File - *.fbp file (which is just an XML file listing every component in your GUI and defining each component‟s properties). Then, the *.fbp file can be converted automatically into a Python *.py file ready to be imported into your Python program. It also serves as Source code generation
  • 3. | 3P a g e other programming languages are supported such as: C++, PHP, Lua and XRC.
  • 4. | 4P a g e Tutorial objective: I will guide you through the basics of wxFormBuilder as used with wxPython generated code. The goal is for you to build a usable First GUI in Python. We are going to create a little application that will take selected text from the user “choice box” and append/print the chosen text to a static text box that has “Hello…” on it. The end result will be a GUI (as sketched below) that just outputs: Hello… World, or Hello… Africa, or Hello… Asia, or Hello… Europe, or Hello… America - on the displayed static text box.
  • 5. | 5P a g e
  • 6. | 6P a g e Prerequisites: We need to have the following packages installed:- ~ Python 2.7 ~ wxpython 3.0.2.0 ~ wxformbuilder 3.5-RC1 ~ Pyinstaller to freeze the application (create an .exe on Windows or a .app on osx) ~ Text editor (Sublime Text, Notepad++, Pycharm or anything similar). Combination of any versions will do as long as they are compatible with each other. I used Python 2.7.10 Anaconda 2.3.0 (64-bit), wxPython 3.0.2.0 (msw-unicode), wxFormBuilder 3.5- RC1 (unicode) and Sublime Text 3. The prerequisite packages most be installed as above in the order mentioned and we should be good to go.
  • 7. | 7P a g e Building the GUI Start wxformbuilder, by default a new project is already opened. Save the new project to your desired directory/folder location on your PC with any name (I used: MyProject.fbp). Set file name to „gui‟ (or whatever name you want) and set code generation to „Python‟ (since we want our GUI to be in wxPython). Add a frame from the “Form” tab. Rename the frame name to "MainFrame" on the Object properties panel. This is optional, but for larger applications it will be necessary to differentiate between frames by their names.
  • 8. | 8P a g e Add a wxBoxSizer from the “Layout” tab. Set “orient” to wxVERTICAL. This will hold our GUI components and stack them vertically
  • 9. | 9P a g e Add a static text (wxSTATICTEXT) from the “Common” tab: From the tool bar, set the static text to “Expand” and “Align Center Horizontally”. From the Object properties panel, set the following properties; Name = HelloText Style = wxALIGN_CENTRE Label = Hello... Font Point Size = 20
  • 10. | 10P a g e Add a drop down box (wxCHOICE) from the “Common” tab: From the tool bar, set the drop down box to “Expand” and “Align Center Horizontally”. From the Object properties panel, set the following properties; Name = choice Choices = World, Africa, America, Asia, Europ Font Point Size = 20
  • 11. | 11P a g e Add a button (wxBUTTON) from the “Common” tab: From the tool bar, set the drop down box to “Expand” and “Align Center Horizontally”. From the Object properties panel, set the following properties; Name = button Label = Print Font Point Size = 20 Bind an event for button clicks since we want to take selected text from the user and append/print the chosen text to a static text box above when the user clicks the button: From the Object properties panel, select “Events” tab and set the OnButtonClick event to “printFunc” (o whatever name you want,
  • 12. | 12P a g e but be sure to remember the name as it is the method/function name that will control the button) Save the wxformbuilder project to your project folder. Then click Generate code from the menu/tool bar or press F8 button on your keyboard.
  • 13. | 13P a g e The content of your project folder should contain the wxformbuilder project file and the generated file. You should end up with a file called “gui.py” in the directory you saved in. This file holds the code for generating the graphics. Run the generated code “gui.py” as follow:- Open the generated file “gui.py” in a text editor (I used sublime text editor) Scroll to the bottom and add the code below;- app = wx.App() frame = MainFrame(None).Show() app.MainLoop() Above is mandatory in wxPython to create an application. It creates an object of MainFrame class and shows/displays it and starts the application on an infinite loop.
  • 14. | 14P a g e Now try running (Ctrl+B for Sublime text) the code and you should see something like this:
  • 15. | 15P a g e Now let‟s modify it to do something when user clicks the “Print” button. Recall that we bind an OnButtonClick event for the button named “printFunc” method/function. Edit the “printFunc” method/function to look like below;- def printFunc( self, event ): hw = self.choice.GetStringSelection() self.HelloText.SetLabel('Hello... ' + hw) self.Layout() The method/function gets the selected text and stores it in a variable “hw”, then appends it to the static text label. The layout is retained by calling the layout method/function. Recall the “choice” and “HelloText” are names of the “drop down box” and “static text” respectively as created earlier.
  • 16. | 16P a g e Building an executable: Now we want to share the application with user who may not have python install on their computers. So we need a way to make our app to run on any computer without python installed on it. This process is generally referred to as "Freezing our Code". The advantage of distributing this way is that your application will work even if the user doesn‟t already have the required version of Python installed. On Windows, and even on many Linux distributions and OSX versions, the right version of Python will not already be installed. One disadvantage is that it will bloat your distribution by about 2MB. Another problem is that your application will not receive any security updates to the version of Python it uses unless you freeze a new version and get users to download it. There are multiple tools to do this as compared in the table below, showing the Solutions and platforms/features supported: http://docs.python-guide.org/en/latest/shipping/freezing/ Solution Windows Linux OS X Python 3 License One- file mode Zipfile import Eggs pkg_resources support bbFreeze yes yes yes no MIT no yes yes yes py2exe yes no no yes MIT yes yes no no pyInstaller yes yes yes yes GPL yes no yes no cx_Freeze yes yes yes yes PSF no yes yes no py2app no no yes yes MIT no yes yes yes
  • 17. | 17P a g e Installing PyInstaller 1- Run the following commands pip install pyinstaller Or python.exe -m pip install pyinstaller 2- Download the PyInstaller package from and run this command from the extracted package directory python setup.py install Building the Executable: From our application folder (directory), open cmd and run the command below;- pyinstaller.exe --onefile --windowed gui.py
  • 18. | 18P a g e
  • 19. | 19P a g e It‟s that easy. If the build was successful, the final executable, gui.exe, and any associated files, will be placed in the dist directory, which will be created if it doesn‟t exist. Let me briefly describe the options that are being used:  --onefile is used to package everything into a single executable. If you do not specify this option, the libraries, etc. will be distributed as separate files alongside the main executable.  --windowed prevents a console window from being displayed when the application is run. If you‟re releasing a non-
  • 20. | 20P a g e graphical application (i.e. a console application), you do not need to use this option.  gui.py the main source file of the application. The base name of this script will be used to name of the executable, however you may specify an alternative executable name using the --name option. Check the PyInstaller Manual for more configuration information. After the build, a gui.spec file will be created. This file contains all of the options used to run PyInstaller, and can be fed back into PyInstaller for future builds in place of the command line options, if desired. To add icon and version text to the exe file, use command below (version.txt will be provided, see the manual);- pyinstaller.exe --onefile --windowed -- icon=srcimgfavicon.ico --version-file=version.txt gui.py Building the Installer: PyInstaller merely assembles the files needed to run your python program; it is not an installer builder. An installer will further compress the app size. There are plenty of good installer builders out there including some that are open source e.g.: NSIS and Inno Setup.
  • 21. | 21P a g e Download the code: The files generated throughout the tutorial can be downloaded from the link below. Size is 25mb https://www.dropbox.com/s/w2e6g7mercdqly0/HelloGUI.zip?dl= 0
  • 22. | 22P a g e Exercise: As an exercise; 1- Add an icon and a title to the title bar? 2- Set a color to the frame‟s background? 3- Add two buttons to exit and reset the app? 4- Finally, add menus to handle the button tasks and to provide help for the app? See final result to the exercise in image below. Solution to this and more are available in video format on this link: www.UmarYusuf.com/wxpy
  • 23. | 23P a g e Good luck, have fun, and I hope my tutorial was useful to you? Thanks for reading! Email: [email protected] Website: www.UmarYusuf.com
  • 24. | 24P a g e Referenced Materials Other tutorials that motivated this post 1- Ultra Quick GUIs with Wxformbuilder/Python by Vighnesh Birodkar https://www.facebook.com/vighnesh.birodkar https://vcansimplify.wordpress.com/2013/04/08/ultra- quick-guis-with-wxformbuilderpython/ 2- Rapidly building a python GUI application by Sebastian Nilsson http://sebastiannilsson.com/en/blogg/rapidly-building- python-gui-application/ 3- How to Install PyQt5 and Build Your First GUI in Python 3.4 http://projects.skylogic.ca/blog/how-to-install-pyqt5-and- build-your-first-gui-in-python-3-4/ 4- Tutorial: Creating GUI Applications in Python with QT by Alex Fedosov http://www.cs.usfca.edu/~afedosov/qttut/ 5- Creating an Executable from a Python Script by Matt Borgerson https://mborgerson.com/creating-an-executable-from-a- python-script