2024-04-26 00:33:05 发布
网友
看起来没有内置的选项来禁用/删除wx.lib.filebrowsebutton.FileBrowseButton中的InputBox/TextCtrl部分,我确实想出了一个解决方法,只需将labelText设置为空白,然后将其缩小到只适合按钮本身,这样从视觉上你就可以看出与普通按钮没有什么区别,但我认为这样做不够好。你知道吗
wx.lib.filebrowsebutton.FileBrowseButton
InputBox/TextCtrl
labelText
那么有没有办法完全禁用/删除InputBox部分呢?或者是一种将普通按钮与文件浏览器功能绑定的方法?你知道吗
InputBox
如果你不需要textctrl,那么你就不需要wx.lib.FileBrowseButton。你只需要一个普通的wx.Button启动一个wx.FileDialog实例。事实上,wx.lib.FileBrowsBbutton就是这么做的。下面是相关的源代码,整个过程可以在这里查看:https://github.com/wxWidgets/wxPython/blob/master/wx/lib/filebrowsebutton.py
textctrl
wx.lib.FileBrowseButton
wx.Button
wx.FileDialog
wx.lib.FileBrowsBbutton
def OnBrowse (self, event = None): """ Going to browse for file... """ current = self.GetValue() directory = os.path.split(current) if os.path.isdir( current): directory = current current = '' elif directory and os.path.isdir( directory[0] ): current = directory[1] directory = directory [0] else: directory = self.startDirectory current = '' dlg = wx.FileDialog(self, self.dialogTitle, directory, current, self.fileMask, self.fileMode) if dlg.ShowModal() == wx.ID_OK: self.SetValue(dlg.GetPath()) dlg.Destroy()
如果你不需要
textctrl
,那么你就不需要wx.lib.FileBrowseButton
。你只需要一个普通的wx.Button
启动一个wx.FileDialog
实例。事实上,wx.lib.FileBrowsBbutton
就是这么做的。下面是相关的源代码,整个过程可以在这里查看:https://github.com/wxWidgets/wxPython/blob/master/wx/lib/filebrowsebutton.py相关问题 更多 >
编程相关推荐