The following code shows two buttons for resizing a window for drawing. The buttons on the left side are changing the size of the window on the right side.
With EVT_PAINT a circle is drawn into this window.
If button B2 is pressed, the window gets larger than the main frame, holding the buttons and the drawing window. Scrollbars will appear to move the window.
If you now move the horizontal scroll bar to the right, the circle will dissapear.
So far so good.
However if (having the circle moved) a focus change happens or the frame gets resized, the circle will be drawn over the B1 button (see picture):
Here is the code showing this behaviour:
#!/usr/bin/env python
import wx
class Frame(wx.Frame):
def __init__(self, *args, **kw):
super(Frame,self).__init__(*args, **kw)
self.Centre()
Gui.window(self,self)
class Gui():
def window(self, frame):
def b1f(ev):
ww.SetSize(300,300)
sw.SetVirtualSize(ww.GetSize())
def b2f(ev):
ww.SetSize(40,40)
sw.SetVirtualSize(ww.GetSize())
def pt(ev):
z = wx.ClientDC(ww)
z.DrawCircle(30,30,30)
pl = wx.Panel(frame)
pls = wx.BoxSizer(wx.HORIZONTAL)
b1 = wx.Button(pl, label='B1')
b2 = wx.Button(pl, label='B2')
b1.Bind(wx.EVT_BUTTON,b1f)
b2.Bind(wx.EVT_BUTTON,b2f)
sw = wx.ScrolledWindow(pl)
sw.SetScrollRate(1,1)
ww = wx.Window(sw,style=wx.SIMPLE_BORDER)
sw.SetVirtualSize(300,300)
sw.Bind(wx.EVT_PAINT,pt)
pls.Add(b1,1,wx.ALIGN_BOTTOM|wx.ALL, 5)
pls.Add(b2,1,wx.ALL, 5)
pls.Add(sw,1,wx.EXPAND|wx.ALL,5)
pl.SetSizer(pls)
if __name__ == '__main__':
app = wx.App()
window = Frame(None)
window.Show()
app.MainLoop()
Is there a way to stop this overdrawing on resizing / refoccusing the main frame?
Many thanks for all tips!