JanDMC hat geschrieben:Hi Leute
ich habe folgendes Problem,
Ich würde gerne ein wx.Image in ein TextCtrl packen.
Das ganze ist sone Art Messanger und das ist das Fenster, indem der Dialog steht, und indem dann auch smileys hinein sollen
FRAGE:
Hat schon jemand das TextCtrl so angepasst , das es Funktioniert wie zb. TextCtrl.addImage() oder so..
mfg JanDMC

Hi,
da mich das selbst auch interessiert, habe ich in wxWidgets Forum gefragt,
und bin mit Hilfe von Jorgen auf eine Lösung gekommen.
http://wxforum.shadonet.com/viewtopic.php?t=7967
Meinen selbstgestrickten Code poste ich hier nochmals:
Code: Alles auswählen
#!/usr/bin/env python
import wx
class MyIconTextCtrl(wx.Panel):
"""MyIconTextCtrl."""
def __init__(self, parent, pos=(50,50), size=(100, 21)):
"""Create the MyIconTextCtrl."""
#create a panel, which looks like a textctrl
wx.Panel.__init__(self, parent, pos=pos, size=size, style=wx.SUNKEN_BORDER)
self.SetBackgroundColour(wx.WHITE)
self.w, self.h = self.GetSize()
#add a bitmap on the left side
bmp = wx.ArtProvider_GetBitmap(wx.ART_FIND, wx.ART_OTHER, (16, 16))
self.staticbmp = wx.StaticBitmap(self, -1, bmp, pos=(1, 0))
w, h = self.staticbmp.GetSize()
#create an invisible textctrl inside the textctrl pane.
self.textctrl = wx.TextCtrl(self, pos=(w + 5, 2), size=(self.w - w - 8, h), style=wx.NO_BORDER)
self.textctrl.Bind(wx.EVT_TEXT_ENTER, self.OnDisplayText)
def OnDisplayText(self, event):
"""Confirm user entered text."""
wx.MessageBox("You Entered: '" + self.textctrl.GetValue() + "'", "Info")
class MyFrame(wx.Frame):
"""TextCtrlWithImage Application Frame."""
def __init__ (self, parent, title):
"""Create the TextCtrlWithImage Application Frame."""
wx.Frame.__init__(self, parent, title=title)
class MyPanel(wx.Panel):
"""TextCtrlWithImage Panel."""
def __init__ (self, parent):
"""Create the TextCtrlWithImage Panel."""
wx.Panel.__init__(self, parent)
MyIconTextCtrl(self)
class MyApp(wx.App):
"""TextCtrlWithImage Application."""
def OnInit(self):
"""Create the TextCtrlWithImage Application."""
frame = MyFrame(None, title="Test: TextCtrl with Image")
panel = MyPanel(frame)
frame.Show(True)
return True
if __name__ == '__main__':
app = MyApp(redirect=False)
app.MainLoop()
Bildchen ist auf:
http://mitglied.lycos.de/drpython/TextCtrlWithImage.png