Search code examples
pythonwxpython

wxpython weird bug for TxtCtrl: box is being "clipped"


When I run the program on Windows, initially I get this weird bug:

enter image description here

As you can see the textbox overlaps the border. However, when I click on the box it fixes itself...didn't see this problem when I ran on mac.

Here is my code :

    panel = wx.Panel(self, wx.ID_ANY)

    self.currentDirectory = os.getcwd()

    menuBar = wx.MenuBar()
    fileMenu = wx.Menu()

    self.pathBox = wx.TextCtrl(panel, pos=(260, 70), size=(240, 20))

    openFileBtn = wx.Button(panel, label="Select Input File", pos=(340, 40))
    openFileBtn.Bind(wx.EVT_BUTTON, self.onOpenFile)
    onGo = wx.Button(panel,label="GO!", pos=(340,220))
    setbold = wx.Font(18, wx.DEFAULT, wx.ITALIC, wx.BOLD)
    onGo.SetFont(setbold)
    self.Bind(wx.EVT_BUTTON, self.onGo)

Solution

  • Try replacing the vertical size of the textctrl with -1, so wx will use the default best size for the height of the widget. If I remember correctly the normal height of single line textctrls on Windows is about 23 pixels, so using 20 will not give it enough room to draw itself the way it wants to.