In this wxPython article we want to learn How to Build Interfaces with wxPython and FlatNotebook, so FlatNotebook is custom control in the wx.lib.agw library for wxPython, which provides notebook like interface with modern flat look. it can be used to create tabs or pages that the user can switch between to display different sets of controls or information. FlatNotebook control offers different customization options such as setting background color of the tabs, color of the active tab and style of the tabs. it also supports drag and drop functionality to reorder or move tabs, and provides events to handle tab related events such as when a tab is selected or closed.
This is the complete code for this article
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 |
import wx import wx.lib.agw.flatnotebook as fnb class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "GeeksCoders - FlatUI Example") self.SetSize((500, 300)) # Create a panel and add FlatUI style panel = wx.Panel(self) panel.SetBackgroundColour(wx.Colour(47, 47, 47)) panel.SetForegroundColour(wx.Colour(255, 255, 255)) panel.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) # Create FlatNotebook and add FlatUI style notebook = fnb.FlatNotebook(panel, wx.ID_ANY, style=fnb.FNB_NO_X_BUTTON) notebook.SetActiveTabColour(wx.Colour(0, 140, 255)) notebook.SetNonActiveTabTextColour(wx.Colour(200, 200, 200)) # Add some pages to notebook page1 = wx.Panel(notebook) page2 = wx.Panel(notebook) page3 = wx.Panel(notebook) notebook.AddPage(page1, "Page 1") notebook.AddPage(page2, "Page 2") notebook.AddPage(page3, "Page 3") # Create sizer and add FlatNotebook to it sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(notebook, 1, wx.EXPAND | wx.ALL, 10) # Set the panel sizer panel.SetSizer(sizer) if __name__ == "__main__": app = wx.App() frame = MainFrame() frame.Show() app.MainLoop() |
In the above example we have created wx.Frame and wx.Panel. than we set the background and foreground colors of panel to give it FlatUI look. we have also set the font for the panel, text control and button. we then creates wx.TextCtrl and wx.Button, and add FlatUI style to them. we add them to a sizer and set the panel sizer to the sizer. and lastly we creates an instance of the MainFrame class and show it.
Run the code and this will be the result
Learn More on wxPython
- PyQt5 Vs wxPython
- PyQt6 Vs wxPython
- Building Python Cross Platform Applications with wxPython
- How to Integrate wxPython with other Python Libraries
- How to Work with Event Handlers with wxPython
- How to Integrate wxPython with Matplotlib
- How to Integrate Yahoo Finance API with wxPython
- How to Build Responsive GUI with wxPython
- How to Style wxPython GUI Applications
- How to Create Custom Widgets in wxPython