如何制作不带标题栏但具有调整边框大小的框架?

时间:2019-06-23 13:24:25

标签: python wxpython

我希望没有标题栏,但可以调整边框大小。 当我尝试此代码时,在框架顶部会创建一个白色的小边框:

class MyFrame(wx.MiniFrame):
    def __init__(self):
        super(MyFrame, self).__init__(
            None, -1, '', (100,100), (200,200), wx.NO_BORDER^wx.RESIZE_BORDER
            )

        self.pnl =wx.Panel(self , -1,(0,0), (200,200), )
        self.pnl.SetBackgroundColour(wx.RED)

        self.closeButton = wx.Button(self.pnl, 1000, 'close',(10,10) ,(50,30))
        self.Bind(wx.EVT_BUTTON, self.quit, self.closeButton)

2 个答案:

答案 0 :(得分:1)

根据定义,您不能声明NO_BORDER和RESIZE_BORDER,如果没有边界,则不能具有可调整大小的边界。
其他人可能会更好地知道,我能得到的最接近的是具有可以调整大小的最小边框。

import wx

class MyFrame(wx.MiniFrame):
    def __init__(self):
        super(MyFrame, self).__init__(
            None, -1, '', (100,100), (200,200), style=wx.RESIZE_BORDER)

        self.pnl =wx.Panel(self , -1,(0,0), (200,200), )
        self.pnl.SetBackgroundColour(wx.RED)

        self.closeButton = wx.Button(self.pnl, 1000, 'close',(10,10) ,(50,30))
        self.Bind(wx.EVT_BUTTON, self.quit, self.closeButton)

    def quit(self,event):
        self.Destroy()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

enter image description here

请注意右下角的采集卡。这样您就可以调整窗口大小

答案 1 :(得分:0)

您可能会发现这很有用。

import wx
class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, -1, pos=(300, 150), size=(320, 250),style=wx.NO_BORDER)
        self.panel = wx.Panel(self)
        self.text = wx.StaticText(self.panel, -1, label="Left click mouse, move and release\nor Move the window")
        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnDown)
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnUp)
        self.panel.Bind(wx.EVT_MOTION, self.OnDrag)
        self.Show()

    def OnDown(self, event):
        x, y = event.GetPosition()
        print("Click coordinates: X=",x," Y=",y)

    def OnUp(self, event):
        x, y = event.GetPosition()
        print("Release coordinates: X=",x," Y=",y)

    def OnDrag(self, event):
        if not event.Dragging():
            return
        x, y = event.GetPosition()
        obj = event.GetEventObject()
        sx, sy = obj.GetScreenPosition()
        self.Move(sx+x,sy+y)

app = wx.App()
window = MyFrame()
app.MainLoop()