import wx
class CustomTitleFrame(wx.Frame):
def __init__(self, parent, title):
super(CustomTitleFrame, self).__init__(parent, title=title, style=wx.DEFAULT_FRAME_STYLE & ~(wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU))
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.InitUI()
def InitUI(self):
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.VERTICAL)
# 自定义标题栏
self.title_panel = wx.Panel(self.panel)
self.title_panel.SetBackgroundColour('#ededed')
title_sizer = wx.BoxSizer(wx.HORIZONTAL)
title_text = wx.StaticText(self.title_panel, label="自定义窗口标题")
title_sizer.Add(title_text, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
self.title_panel.SetSizer(title_sizer)
vbox.Add(self.title_panel, 0, wx.EXPAND | wx.ALL, 0)
# 内容部分
content_panel = wx.Panel(self.panel)
content_panel.SetBackgroundColour('#ededed')
vbox.Add(content_panel, 1, wx.EXPAND | wx.ALL, 0)
self.panel.SetSizer(vbox)
def OnClose(self, event):
self.Destroy()
app = wx.App(False)
frame = CustomTitleFrame(None, '自定义标题窗口')
frame.Show()
app.MainLoop()