在WxPython中检查文件保存对话框中的覆盖选项

1 投票
1 回答
1821 浏览
提问于 2025-04-16 18:17

我想在使用文件保存对话框保存文件时,检查一下同名的文件是否已经存在。如果存在的话,就不让我保存,并强制我改个名字。我该怎么在WxPython中实现这个功能呢?

谢谢大家的帮助。

以下是我的保存代码:

        #Dosya tipi filtreleri
        wildcard = "BENGI files (*.bengi)|*.bengi|"    \
       "SQLITE file (*.sdb)|*.sdb|"        \
       "All files (*.*)|*.*"

        dlg = wx.FileDialog(
            self, message="Save file as ...", defaultDir=DesktopPath, 
            defaultFile="_nokta_listesi", wildcard=wildcard, style=wx.SAVE
            )


        # Varsayılan dosya tipi filtresi
        dlg.SetFilterIndex(0)

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()

            # Create a database in disk
            con=apsw.Connection(path)

            # Copy from memory to disk
            with con.backup("main", self.conn2, "main") as backup:
                backup.step() # copy whole database in one go

            con.close(True) 
        dlg.Destroy()

1 个回答

3

解决了:

我在样式中添加了“wx.OVERWRITE_PROMPT”这个标志。

撰写回答