wxpython->图片显示不完整

redstoneleo 2012-09-12 10:42:57
wxpython->图片显示不完整

主要是运行后显示的图片仿佛边缘被裁减过的样子。谁能解释一下原因?


#!/usr/bin/env python

"""Hello, wxPython! program."""

import wx

class Frame(wx.Frame):
"""Frame class that displays an image."""

def __init__(self, image):
"""Create a Frame instance and display image."""
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent=None, id=-1, title='Hello, wxPython!',
pos=wx.DefaultPosition,size=size)
self.panel = wx.Panel(self)
wx.StaticBitmap(parent=self.panel, bitmap=temp)
self.Centre()

class App(wx.App):
"""Application class."""

def OnInit(self):
image = wx.Image('img.jpg', wx.BITMAP_TYPE_JPEG)
self.frame = Frame(image)
self.frame.Show()
self.SetTopWindow(self.frame)
return True

def main():
app = App()
app.MainLoop()

if __name__ == '__main__':
main()


...全文
149 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2012-09-13
  • 打赏
  • 举报
回复
你设置的是整个窗口尺寸,含边框抬头等自然略有不足。可以加行代码:
self.SetClientSize(size)
angel_su 2012-09-13
  • 打赏
  • 举报
回复
考虑你有很多控件的时候,自己算很麻烦吧,所以一般是建议采用sizer方式布局方式,让程序自己去计算,譬如你的代码可以改成下面,不用管图片大小,只要求panel占满空间:
    def __init__(self, image):
"""Create a Frame instance and display image."""
temp = image.ConvertToBitmap()
#~ size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent=None, id=-1, title='Hello, wxPython!')#, pos=wx.DefaultPosition,size=size)
#~ pos=wx.DefaultPosition,size=size)
self.panel = wx.Panel(self)
wx.StaticBitmap(parent=self.panel, bitmap=temp)
sizer = wx.BoxSizer()
sizer.Add(self.panel, 1, wx.EXPAND)
self.SetSizerAndFit(sizer)
self.Centre()

redstoneleo 2012-09-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
你设置的是整个窗口尺寸,含边框抬头等自然略有不足。可以加行代码:
self.SetClientSize(size)
[/Quote]有没有什么方法可以直接设置frame的size参数,使得图片完整地显示出来?

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧