Reputation: 11
My wxPython dirPickerCtrl text box is appearing over the top of its browse button.
My code is:
class chooseFolder(wx.DirPickerCtrl):
def __init__(self, *args, **kwargs):
wx.DirPickerCtrl.__init__(self, *args, **kwargs)
dataFolder = chooseFolder(self, -1, message= 'Choose Folder', pos = (55,24),
style= wx.DIRP_DEFAULT_STYLE,
size = (250, 25))
I have tried applying different sizers in that panel to see if that solves it but to no avail.
I am using wx version 4.0.3
EDIT: Below is a minimal code example to demonstrate the problem I am having, shown in the second picture.
import wx
import os
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.panel = wx.Panel(self, -1)
chooseFolder(parent=self,
pos = (10,100),
style= wx.DIRP_DEFAULT_STYLE,
size = (250, 30))
self.Centre()
self.Show()
class chooseFolder(wx.DirPickerCtrl):
def __init__(self, *args, **kwargs):
wx.DirPickerCtrl.__init__(self, *args, **kwargs)
if __name__ == "__main__":
app = wx.App()
ButtonFrame()
app.MainLoop()
picture of text box on top of button
EDIT: Picture of output from minimal code example
Upvotes: 1
Views: 320
Reputation: 1312
I think the problem comes from the size
given to the constructor. Try setting the height (second parameter of size
) to -1
.
Upvotes: 0
Reputation: 22458
Edit based on code sample supplied:
I cannot test on Windows but it looks as if it may be a bug (it works on Linux).
Do you get the same result if you don't sub-class DirPickerCtrl
but use it directly? Like this:
import wx
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.panel = wx.Panel(self, -1)
chooseFolder = wx.DirPickerCtrl(self.panel, -1, pos = (10,100), path = "",
style= wx.DIRP_DEFAULT_STYLE,
size = (250, 30))
# chooseFolder(parent=self,
# id = -1,
# pos = (10,100),
# path = "/home",
# style= wx.DIRP_DEFAULT_STYLE)#,
# #size = (250, 30))
self.Centre()
self.Show()
#class chooseFolder(wx.DirPickerCtrl):
# def __init__(self, *args, **kwargs):
# wx.DirPickerCtrl.__init__(self, *args, **kwargs)
if __name__ == "__main__":
app = wx.App()
ButtonFrame()
app.MainLoop()
You mention that you have tried applying sizers to the panel but in the question, there is no reference to a panel at all.
Try playing with the code below and see if it helps.
For simplicity, it relies solely on fixed positions (no sizers).
import wx
import os
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None)
self.panel = wx.Panel(self, -1)
self.BtnPressHere = wx.Button(self.panel, -1, "Press Here", pos=(10,10))
self.BtnPressHere.Bind(wx.EVT_BUTTON, self.OnPress)
self.Bind(wx.EVT_DIRPICKER_CHANGED, self.DirChange)
self.Centre()
self.Show()
print("Current Dir: ",os.getcwd())
def OnPress(self,event):
dataFolder = chooseFolder(parent=self,
id=-1,
path='/home',
message='Choose Folder',
pos = (10,100),
style= wx.DIRP_DEFAULT_STYLE|wx.DIRP_CHANGE_DIR,
size = (250, 30))
def DirChange(self,event):
print("Dir changed to: ", event.GetPath())
print("Checking Current Dir: ",os.getcwd())
class chooseFolder(wx.DirPickerCtrl):
def __init__(self, *args, **kwargs):
wx.DirPickerCtrl.__init__(self, *args, **kwargs)
if __name__ == "__main__":
app = wx.App()
ButtonFrame()
app.MainLoop()
Upvotes: 1