wxPython删除窗口边框

时间:2017-11-06 06:14:55

标签: python image wxpython border

我使用了原始来源的代码 - How to resize and draw an image using wxpython?

问题是如何使用param-wx.NO_BORDER或wx.BORDER_NONE显示没有边框的窗口?

frame = wx.Frame(None, -1, 'Scaled Image', style= wx.BORDER_NONE)

当我使用它时,图像显示在左上角切割,有任何建议吗?

像这样:

result

def scale_bitmap(bitmap, width, height):
    image = wx.ImageFromBitmap(bitmap)
    image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH)
    result = wx.BitmapFromImage(image)
    return result

class Panel(wx.Panel):
    def __init__(self, parent, path):
        super(Panel, self).__init__(parent, -1)
        bitmap = wx.Bitmap(path)
        bitmap = scale_bitmap(bitmap, 100, 100)
        control = wx.StaticBitmap(self, -1, bitmap)
        # control.SetPosition((10, 10))

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Scaled Image', style= wx.BORDER_NONE)
    panel = Panel(frame, 'onewayr.jpg')
    frame.SetPosition((100, 100))
    frame.Show()
    app.MainLoop()

1 个答案:

答案 0 :(得分:0)

您将使用以下方式获取指定大小的图片:

control = wx.StaticBitmap(parent, -1, bitmap)

然而,这不是定义面板和框架的规范方式。最常见的是,Frame具有sizer,Panel位于sizer的插槽中。 sizer完成定位和扩展面板内容的所有工作。

例如(使用wxPython Phoenix版本):

import wx

def scale_bitmap(impath, width, height):
    image = wx.Image(impath, wx.BITMAP_TYPE_JPEG)
    image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH)
    result = wx.Bitmap(image)
    return result

class Panel(wx.Panel):
    def __init__(self, parent, impath=None):
        super(Panel, self).__init__(parent, -1)
        bitmap = scale_bitmap(impath, 100, 100)
        self.control = wx.StaticBitmap(self, -1, bitmap)


class MyFrame(wx.Frame):
    def __init__(self, parent, imgpath=None): 
        wx.Frame.__init__(self, parent, -1, style=wx.BORDER_NONE)
        self.panel = Panel(self, imgpath)
        self.panel.SetBackgroundColour('red')

        self.SetSize(150,150)
        self.SetPosition((100,100))

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.panel, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Layout()


if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, imgpath=r'C:/Users/joaquin/Desktop/llave.jpg') 
    frame.Show()
    app.MainLoop()

在这里,我给面板一个红色,表示它填充了150x150帧的所有空间,而缩放到100x100的图片位于面板上的默认位置(左上角)。

enter image description here