wxpython:如何在文本控件中添加图像
wxpython: How to add am image in text control
我正在尝试在文本控件中显示图像,但它只显示二进制字符。
但是他们有什么方法可以让我在 wxpython 中存档这个或它不可能实现的梦想
请帮助我需要这个代理。
提前谢谢
这是我目前拥有的源代码
import wx
class MainFrame(wx.Frame):
def __init__(self,*args,**kwargs):
super(MainFrame,self).__init__(*args,**kwargs)
self.main_panel = MainPanel(self,-1)
class MainPanel(wx.Panel):
def __init__(self,*args,**kwargs):
super(MainPanel,self).__init__(*args,**kwargs)
img1 = wx.Image("coins.png", wx.BITMAP_TYPE_ANY)
w = img1.GetWidth()
h = img1.GetHeight()
img1 = img1.Scale(w/2, h/2)
sb1 = wx.StaticBitmap(self, -1, wx.BitmapFromImage(img1))
self.txtctrl = wx.TextCtrl(self,-1,"display image here",size=(500,300),pos=(20,10))
class App(wx.App):
def OnInit(self):
mainframe = MainFrame(None,-1,title="Display image in txt ctrl",size=(600,400))
mainframe.Show()
mainframe.Center()
return True
if __name__ == "__main__":
app = App();
app.MainLoop()
你可以用 wx.Image 阅读 this
你还可以看一个更复杂的例子here
您不能将图像直接放入常规 wx.TextCtrl
小部件中。这目前是不可能的,因为他们不支持。但是,您可以将图像放入 RichTextCtrl
小部件中。如果您还没有下载它,请务必从项目的 website 获取 wxPython 演示,因为它有一个很好的示例。这里有几个链接:
- http://wxpython.org/Phoenix/docs/html/richtext.RichTextCtrl.html
- http://play.pixelblaster.ro/blog/archive/2008/10/08/richtext-control-with-wxpython-saving-and-loading
如果您只想在您的应用程序中放一张图片,那么 wx.Image
是您的朋友(正如 John 已经提到的)。
我正在尝试在文本控件中显示图像,但它只显示二进制字符。
但是他们有什么方法可以让我在 wxpython 中存档这个或它不可能实现的梦想
请帮助我需要这个代理。 提前谢谢
这是我目前拥有的源代码
import wx
class MainFrame(wx.Frame):
def __init__(self,*args,**kwargs):
super(MainFrame,self).__init__(*args,**kwargs)
self.main_panel = MainPanel(self,-1)
class MainPanel(wx.Panel):
def __init__(self,*args,**kwargs):
super(MainPanel,self).__init__(*args,**kwargs)
img1 = wx.Image("coins.png", wx.BITMAP_TYPE_ANY)
w = img1.GetWidth()
h = img1.GetHeight()
img1 = img1.Scale(w/2, h/2)
sb1 = wx.StaticBitmap(self, -1, wx.BitmapFromImage(img1))
self.txtctrl = wx.TextCtrl(self,-1,"display image here",size=(500,300),pos=(20,10))
class App(wx.App):
def OnInit(self):
mainframe = MainFrame(None,-1,title="Display image in txt ctrl",size=(600,400))
mainframe.Show()
mainframe.Center()
return True
if __name__ == "__main__":
app = App();
app.MainLoop()
你可以用 wx.Image 阅读 this
你还可以看一个更复杂的例子here
您不能将图像直接放入常规 wx.TextCtrl
小部件中。这目前是不可能的,因为他们不支持。但是,您可以将图像放入 RichTextCtrl
小部件中。如果您还没有下载它,请务必从项目的 website 获取 wxPython 演示,因为它有一个很好的示例。这里有几个链接:
- http://wxpython.org/Phoenix/docs/html/richtext.RichTextCtrl.html
- http://play.pixelblaster.ro/blog/archive/2008/10/08/richtext-control-with-wxpython-saving-and-loading
如果您只想在您的应用程序中放一张图片,那么 wx.Image
是您的朋友(正如 John 已经提到的)。