wxPython删除窗口边框 [英] wxPython remove window border
问题描述
我使用了原始来源的代码 -
def scale_bitmap(位图,宽度,高度):
image = wx.ImageFromBitmap(bitmap)
image = image.Scale(width, height,wx.IMAGE_QUALITY_HIGH)
result = wx.BitmapFromImage(image)
返回结果
class Panel(wx.Panel):
def __init __(self,parent ,路径):
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()
您将使用以下方式获取指定大小的图片:
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)
返回结果
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 =无):
wx.Frame .__ init __(self,parent,-1,style = wx.BORDER_NONE)
self.panel = Panel(self,imgpath)
self.panel。 SetBackgroundColour('red')
self.SetSize(150,150)
self.SetPosit ion((100,100))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panel,1,wx.EXPAND)
self.SetSizer( sizer)
self.Layout()
如果__name__ =='__ main__':
app = wx.App()
frame = MyFrame(无,imgpath = r'C:/Users/joaquin/Desktop/llave.jpg')
frame.Show()
app.MainLoop()
在这里,我给面板一个红色,表示它填充了150x150帧的所有空间,同时缩放到100x100的图片被定位在面板上的默认位置(左上角)。
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).
这篇关于wxPython删除窗口边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!