Frage

I have created a pop up window, but the TextCtrl is not fully expanded to fill up the window. It works great if I use StaticText instead, (but if content too large then I would need the scroll bar, that is why I am using TextCtrl now). Please provide some guidance.

self.description = WindowPopup(self, wx.SIMPLE_BORDER, content)
btn = event.GetEventObject()
dw = wx.DisplaySize()[0]
width = self.description.GetSize()[0]
y = btn.ClientToScreen((0,0))[1]
height =  btn.GetSize()[1]
x = dw - width - 20 - 10
self.description.Position((x, y), (0, height))
self.description.Show(True)

class WindowPopup(wx.PopupWindow):
   """ Pops up a window to provide description for the selection """
   def __init__(self, parent, style, content):
      wx.PopupWindow.__init__(self, parent, style)

      self.SetSize((700, 287))
      panel = wx.Panel(self)
      sizer = wx.BoxSizer(wx.VERTICAL)
      st = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE | wx.TE_READONLY)
      st.SetValue(content)
      sizer.Add(st, 0, wx.EXPAND)
      panel.SetSizer(sizer)
War es hilfreich?

Lösung 2

The actual answer is:

sizer = wx.BoxSizer(wx.VERTICAL)
st = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE | wx.TE_READONLY, size = (500, 174))
st.SetValue(content)
self.SetSize((500, 174))
sizer.Add(st, 0, wx.EXPAND)
self.SetSizer(sizer)
self.Layout()
self.Show(True)

Credits to Joran for noticing Layout().

PopupWindow does not require an additional panel, because the window itself can have sizer set to it. This has been realized by using the wxPython Widget Inspection Tool.

Make sure TextCtrl and PopupWindow have the same size.

Andere Tipps

I suspect your problem is that the panel is not as big as the popupwindow ... so even though the textfield is expanding to fill its sizer area it is not filling the popup its self.

try using something like

def __init__(...):
     ...
     self.SetMinSize((700,287))
     sizer2 = wx.BoxSizer()
     sizer2.Add(panel)
     self.SetSizer(sizer2)

also make sure that you are calling layout on it at some point (note this is totally untested... so it may need some tweeks, or even worse just be wrong...)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top