Odd visual artifact

In MDIChild toolbar I have a button and a search control. When the frame opens there is a small blank square in the top left corner of the button and the text control part of the search control is colored with the frame’s background color. Both artifacts go away by hovering the mouse over them. This is on a Windows 10 box. Here’s a pic:

It looks like you have controls that are not managed by the frame sizer.

Hi. Thanks for the reply. Not sure what you mean though. Don’t the controls have to be in a panel? Let me just include the code:

class ProjectListWindow(wx.MDIChildFrame):
	def __init__(self, parent, win_id, title, data):
			wx.MDIChildFrame.__init__(self, parent, win_id, title,
									  size=(900, 500))

			self.panel = wx.Panel(self)
			self.panel.SetBackgroundColour(wx.Colour(92, 61, 70))

			tbPanel = wx.Panel(
				self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize
			tbPanel.SetBackgroundColour(wx.Colour(153, 191, 170))

			addBtn = wx.Button(tbPanel, wx.ID_ANY, label='Add Project',
			addBtn.Bind(wx.EVT_BUTTON, self.on_addBtn_click)

			srchCtl = wx.SearchCtrl(tbPanel, wx.ID_ANY, '', size=(-1, 30))

			tbSizer = wx.BoxSizer(wx.HORIZONTAL)
			tbSizer.Add(addBtn, 0, wx.ALL, 5)
			tbSizer.Add(srchCtl, 0, wx.ALL, 5)

			grdPanel = wx.Panel(
				self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize
			grdPanel.SetBackgroundColour(wx.Colour(86, 134, 141))
			self.grid = wx.grid.Grid(grdPanel, wx.ID_ANY)
			self.grid.CreateGrid(len(data), 5)
			self.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_cell_click)
			font = self.grid.GetCellFont(0, 1)
			self.grid.SetColSize(1, get_widest_text_dimension(
				[row['nickname'] for row in data],
				font.GetFaceName(), font.GetPointSize()
			self.grid.SetColSize(4, 400)
			grdSizer = wx.BoxSizer(wx.HORIZONTAL)
			grdSizer.Add(self.grid, 0, wx.ALL, 5)

			frameSizer = wx.BoxSizer(wx.VERTICAL)
			frameSizer.Add(tbPanel, 0, wx.EXPAND | wx.ALL, 10)
			frameSizer.Add(grdPanel, 0, wx.EXPAND | wx.ALL, 10)


			self.Bind(wx.EVT_CLOSE, self.on_close)

Big clue: This does not happen when I launch a Frame or Dialog. Only happens on an MDIChildFrame. Might rethink as an SDI.

Try adding something like wx.CallAfter(tbPanel.Refresh) so an extra repaint will be done on that panel and its children shortly after all the creation of the widgets is done. Sometimes you can get artifacts like that when creating and moving a bunch of items in a visible window as some Windows optimizations may cause some initial paints to be skipped. Or something like that.

OTOH, MDI really isn’t used much anymore. It’s nice from our (developers) perspective, but a big chunk of typical users do not like it at all.

I reproduced the problem locally using your code. I fixed the problem by replacing self.panel.SetSizer(frameSizer)with self.panel.SetSizerAndFit(frameSizer).

1 Like

Sweet! Thank you, you are a prince among coders.

BTW, this trick fixed the same problem in a tabbed panel.