简体   繁体   中英

wxPython remove window border

I used the code from original source - How to resize and draw an image using wxpython?

The question is how to display window without border, with param-wx.NO_BORDER or wx.BORDER_NONE?

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

When I use it the image shows cut in left upper corner, any suggestions?

Like this :

结果

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()

You will get the picture at the specified size using:

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

This, however, is not the canonical way of defining Panels and Frames. Most commonly, the Frame has sizers and the Panel is located in a slot of the sizer. The sizer do all the job of positioning and expanding the contents of the panel.

For example (Using wxPython Phoenix version):

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()

Here I gave a red color to the Panel to show that it fills all the space of the 150x150 Frame while the picture, which was scaled to 100x100, is positioned at a default position on the Panel (upper left).

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM