我有一个小型液晶显示屏,打开的文件对话框太大了。 有没有办法指定固定大小?
dlg = wx.FileDialog(self, _("Open file to print"), basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST )
此致 朱塞佩
答案 0 :(得分: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()