Gettin started with PyQt, wxPython and pythonOCC

In this sample, we will set up a simple application that:

  • create a menu and 2 menus items,
  • these 2 menu items create a box for the first one, and a cylinder for the second one,
  • for both wxPython and PyQt

We first call the SimpleGui module, that provides a simple interface to design GUI for both PyQt, pySide and wxPython:

from OCC.Display.SimpleGui import init_display

If you want to use wxPython, just set the backend as following

display, start_display, add_menu, add_function_to_menu = init_display("wx")

Change the “wx” string to “pyqt” or “pyqt-pyside”. If you don’t provide any string, the default GUI manager available on

your system will be used.

Let’s now define the two functions that create and display a box and a cylinder:

def simple_test(event=None):

def simple_cylinder(event=None):
	from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder
	s = BRepPrimAPI_MakeCylinder(60, 200).Shape()

Now we create a menu named ‘simple test’ and add the two functions into submenus:

add_menu('simple test')
add_function_to_menu('simple test',simple_test)
add_function_to_menu('simple test',simple_cylinder)

Finally, ask the display to be rendered:

# display loop