wxPython : How do I shrink the size of Button to the width of the label text?

StackOverflow https://stackoverflow.com/questions/23557202

  •  18-07-2023
  •  | 
  •  

Вопрос

I have a FlexGridSizer that I add a bunch of TextCtrl to, some of which are for users to enter a path, so I have a Button in the adjacent column to the right of those TextCtrl boxes. The label text is ... and I only call AddGrowableCol on the columns with TextCtrl in them... here is how I'm adding the Button in my for loop (I don't use addmany):

widgetItem = wx.Button(parent, -1, "...")
widgetItem.row=rowNum
widgetItem.col=colNum
widgetItem.target = lastTextBox
self.Bind(wx.EVT_BUTTON, self.getFile, widgetItem)
currentSizer.AddF(widgetItem, wx.SizerFlags(0).Border(wx.ALL, 5))
Это было полезно?

Решение

Ah, what I was thinking would be called shrink-wrapped or shrink-to-fit, is called exactfit by wxPython: wxPython docs on Button class, style section

wx.BU_EXACTFIT

here is how I had to instantiate the Button:

widgetItem = wx.Button(parent, -1, "...", style=wx.BU_EXACTFIT)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top