如何设置wx.FileDialog窗口大小?
我有一个小的LCD屏幕,但是打开文件的对话框太大了。有没有办法让它的大小固定呢?
dlg = wx.FileDialog(self, _("Open file to print"), basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST )
祝好,Giuseppe
1 个回答
0
你可以尝试用一个大小的元组来调用对话框的 SetSize() 方法。不过,如果默认的对话框不支持调整大小,这个方法可能就不管用。例如,在 Windows 系统上,我发现创建对话框时,无法把它的大小缩小太多。不过,下面有一些代码供你试试:
import wx
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Dialogs")
panel = wx.Panel(self)
btn = wx.Button(panel, label="Open Dialog")
btn.Bind(wx.EVT_BUTTON, self.openFileDlg)
#----------------------------------------------------------------------
def openFileDlg(self, event):
""""""
wildcard = "Python source (*.py)|*.py|" \
"All files (*.*)|*.*"
dlg = wx.FileDialog(
None, message="Choose a file",
defaultDir="/",
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
)
dlg.SetSize((100,100))
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetPaths()
print "You chose the following file(s):"
for path in paths:
print path
dlg.Destroy()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()