In this Python GUI article i want to show you creating PrintDialog in wxPython. so using a PrintDialog, you will have a nice dialog for printing documents.
Also you can check More GUI Development Tutorials in the below link.
1: PyQt5 GUI Development Tutorials
2: TKinter GUI Development Tutorials
3: Pyside2 GUI Development Tutorials
4: Kivy GUI Development Tutorials
So now this is the complete code for Python GUI PrintDialog in wxPython
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import wx class MyFrame(wx.Frame): def __init__(self, parent, title): super(MyFrame, self).__init__(parent, title =title, size = (800,600)) self.panel = MyPanel(self) class MyPanel(wx.Panel): def __init__(self, parent): super(MyPanel, self).__init__(parent) self.button = wx.Button(self, label = "Print Dialog", pos = (100,100)) self.Bind(wx.EVT_BUTTON, self.openDialog) def openDialog(self, event): data = wx.PrintDialogData() data.EnableSelection(True) data.EnablePrintToFile(True) data.EnablePageNumbers(True) data.SetMinPage(1) data.SetMaxPage(10) dialog = wx.PrintDialog(self, data) #dialog.ShowModal() if dialog.ShowModal() == wx.ID_OK: data = dialog.GetPrintDialogData() print('GetAllPages: %d\n' % data.GetAllPages()) dialog.Destroy() class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(parent=None, title="Print Dialog") self.frame.Show() return True app = MyApp() app.MainLoop() |
At the top we have created our MyFrame. this class is a top level window that inherits from wx.Frame and we create the object of our MyPanel class in here.
1 2 3 4 5 6 | class MyFrame(wx.Frame): def __init__(self, parent, title): super(MyFrame, self).__init__(parent, title =title, size = (800,600)) self.panel = MyPanel(self) |
This is our MyPanel class that inherits from wx.Panel and we create a button in this class also we create the event binding process in this class.
1 2 3 4 5 6 7 | class MyPanel(wx.Panel): def __init__(self, parent): super(MyPanel, self).__init__(parent) self.button = wx.Button(self, label = "Print Dialog", pos = (100,100)) self.Bind(wx.EVT_BUTTON, self.openDialog) |
This is method is for creating of our PrintDialog, and at the top you can see that we have bonded this method with our button. so when a person click on the button a PrintDialog will be opened.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | def openDialog(self, event): data = wx.PrintDialogData() data.EnableSelection(True) data.EnablePrintToFile(True) data.EnablePageNumbers(True) data.SetMinPage(1) data.SetMaxPage(10) dialog = wx.PrintDialog(self, data) #dialog.ShowModal() if dialog.ShowModal() == wx.ID_OK: data = dialog.GetPrintDialogData() print('GetAllPages: %d\n' % data.GetAllPages()) dialog.Destroy() |
So the last class is MyApp class that inherits from wx.App. the OnInit() method is where you will most often create frame subclass objects. and start our main loop.That’s it. Once the application’s main event loop processing takes over, control passes to wxPython. Unlike procedural programs, a wxPython GUI program primarily responds to the events taking place around it, mostly determined by a human user clicking with a mouse and typing at the keyboard. When all the frames in an application have been closed, the app.MainLoop() method will return and the program will exit.
1 2 3 4 5 6 7 8 9 10 | class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(parent=None, title="Print Dialog") self.frame.Show() return True app = MyApp() app.MainLoop() |
So run the code and this will be the result

Also you can watch the complete video for this article
How can I pass this code to Tkinter?
you can see my tkinter tutorials