wxPython Tutorial – Creating ToolBar

In this wxPython Tutorial we want to talk about Creating 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 toolbar is easy and simple, you can just use wx.ToolBar class for creating toolbar.

 

 

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

wxPython Tutorial - Creating ToolBar
wxPython Tutorial – Creating ToolBar

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×