How to Create ToolBar in wxPython

In this wxPython article we want to learn How to Create ToolBar in wxPython, Toolbars provides a quick and easy way for users to access the most commonly used features of an application. in wxPython creating a toolbar is a simple process that involves using wx.ToolBar class.

 

 

First of all we need to import the required modules from wxPython.

 

 

After that we creates the main frame of our application. this will serve as the container for the toolbar and other GUI components, in the above code we creates the main frame of our application by inheriting from wx.Frame class. we set the title of the frame and its size. after that we define InitUI() method, after that we creates the toolbar using CreateToolBar() method of the frame. we add a tool to the toolbar using AddTool() method, which takes a tool identifier, label and an optional bitmap. we also call the Realize() method of the toolbar to display the toolbar. we bind OnExit() method to the tool using the Bind() method, and we show the frame using the Show() method.

 

 

 

OnExit() method is responsible for handling the tool event. when the user clicks on the tool, we want to exit the application. we do this by calling the Close() method of the frame.

 

 

To run the application, we need to create an instance of our main frame class and start the wxPython event loop.

 

 

 

This is the complete code for this article

 

 

 

Run the code and this will be the result

How to Create ToolBar in wxPython
How to Create ToolBar in wxPython

 

 

You can learn more on wxPython

Leave a Comment