wx.Frame.__init__(self, parent, id, title, style = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.FRAME_EX_CONTEXTHELP)
当修改了style,改成如下时,界面就显示不正常了,整个窗口都变灰了,上面的各种控件都看不见了,不知道什么原因,
wx.Frame.__init__(self, parent, id, title, style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
我的目的就是不想用标准的标题栏。
4 个解决方案
#1
源代码如下,
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.frame = parent
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def OnEraseBackground(self, evt):
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("bg1.jpg")
dc.DrawBitmap(bmp, 0, 0)
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='Test App'):
wx.Frame.__init__(self, parent, id, title, style = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.FRAME_EX_CONTEXTHELP)
self.SetClientSize((800, 600))
self.Center()
self.panel = MyPanel(self)
self.txtShow = wx.StaticText(self.panel, label="Test text:", pos=(20, 120))
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame();
frame.Show()
app.MainLoop()
上面的代码可以正常显示,但是当我把创建Frame的那行语句修改成下面这句时,就显示不正常了,整个画面都是灰色的,只有窗口左上角有一小块白色的,不知道为什么会这样?
wx.Frame.__init__(self, parent, id, title, style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.frame = parent
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def OnEraseBackground(self, evt):
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("bg1.jpg")
dc.DrawBitmap(bmp, 0, 0)
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='Test App'):
wx.Frame.__init__(self, parent, id, title, style = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.FRAME_EX_CONTEXTHELP)
self.SetClientSize((800, 600))
self.Center()
self.panel = MyPanel(self)
self.txtShow = wx.StaticText(self.panel, label="Test text:", pos=(20, 120))
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame();
frame.Show()
app.MainLoop()
上面的代码可以正常显示,但是当我把创建Frame的那行语句修改成下面这句时,就显示不正常了,整个画面都是灰色的,只有窗口左上角有一小块白色的,不知道为什么会这样?
wx.Frame.__init__(self, parent, id, title, style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
#2
wx.FRAME_SHAPED是创建不规则窗口,应该不需要wx.Panel。貌似你只是不要标题栏,那么试试style=wx.CLIP_CHILDREN
#3
如果不需要wx.Panel,那所有控件的parent就是wx.Frame了?
#4
style=wx.CLIP_CHILDREN 试了,还是不行;不用wx.Panel的确就行了,为什么不规则窗口就不能用wx.Panel呢?
#1
源代码如下,
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.frame = parent
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def OnEraseBackground(self, evt):
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("bg1.jpg")
dc.DrawBitmap(bmp, 0, 0)
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='Test App'):
wx.Frame.__init__(self, parent, id, title, style = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.FRAME_EX_CONTEXTHELP)
self.SetClientSize((800, 600))
self.Center()
self.panel = MyPanel(self)
self.txtShow = wx.StaticText(self.panel, label="Test text:", pos=(20, 120))
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame();
frame.Show()
app.MainLoop()
上面的代码可以正常显示,但是当我把创建Frame的那行语句修改成下面这句时,就显示不正常了,整个画面都是灰色的,只有窗口左上角有一小块白色的,不知道为什么会这样?
wx.Frame.__init__(self, parent, id, title, style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.frame = parent
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def OnEraseBackground(self, evt):
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("bg1.jpg")
dc.DrawBitmap(bmp, 0, 0)
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='Test App'):
wx.Frame.__init__(self, parent, id, title, style = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.FRAME_EX_CONTEXTHELP)
self.SetClientSize((800, 600))
self.Center()
self.panel = MyPanel(self)
self.txtShow = wx.StaticText(self.panel, label="Test text:", pos=(20, 120))
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame();
frame.Show()
app.MainLoop()
上面的代码可以正常显示,但是当我把创建Frame的那行语句修改成下面这句时,就显示不正常了,整个画面都是灰色的,只有窗口左上角有一小块白色的,不知道为什么会这样?
wx.Frame.__init__(self, parent, id, title, style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
#2
wx.FRAME_SHAPED是创建不规则窗口,应该不需要wx.Panel。貌似你只是不要标题栏,那么试试style=wx.CLIP_CHILDREN
#3
如果不需要wx.Panel,那所有控件的parent就是wx.Frame了?
#4
style=wx.CLIP_CHILDREN 试了,还是不行;不用wx.Panel的确就行了,为什么不规则窗口就不能用wx.Panel呢?