为什么我无法运行 .exe 转换后的 wxPython 文件?属性错误

发布于 2024-12-09 15:46:24 字数 2954 浏览 3 评论 0原文

这是我得到的输出:

Traceback (most recent call last):
    File "ConvertImagesWithInterface.py", line 1, in (module)
    File "wx\__init__.pyc", line 45, in (module)
    File "wx\_core.pyc", line 5, in (module)
    File "new.pyc", line 3, in (module)
AttributeError: 'module' object has no attribute 'Frame'

我尝试将 __init__ 文件和 new.pyc 文件复制到与(模块)位置相关的不同目录中,尝试重命名模块内部的内容,并查看了其他人遇到的大约 20 个不同的问题,但我找不到如何解决这个问题的答案。有人有什么想法吗?

提前致谢。

import wx as wxPython
import os

try:
# Python2
import Tkinter as tk
import tkFileDialog as tkfd

except ImportError:
# Python3
import tkinter as tk
import tkinter.filedialog as tkfd

newFileName = "" 
newFolderName = "new folder/"
newDirectory = "" 
path = ""
jpgType = ".jpg"
pngType = ".png"
filesConverted = ""
numberOfFiles = 0

类格雷格(wxPython.Frame):

def __init__(self, parent, id):
    wxPython.Frame.__init__(self, parent, id, 'Convert Images', size = (160, 110))
    panel = wxPython.Panel(self)

    button = wxPython.Button(panel, label = "exit", pos = (10, 10), size = (60, 60))
    self.Bind(wxPython.EVT_BUTTON, self.closebutton, button)
    self.Bind(wxPython.EVT_CLOSE, self.closewindow)

    button = wxPython.Button(panel, label = "convert", pos = (80, 10), size = (60, 60))
    self.Bind(wxPython.EVT_BUTTON, self.file_open, button)



def closebutton(self, event):
    self.Close(True)

def closewindow(self, event):
    self.Destroy()

def file_open(self, event):
    root = tk.Tk()
    root.withdraw() 
    path = tkfd.askdirectory(parent=root,initialdir="/",title='Please select a directory') + "/"

    directoryFiles = os.listdir(path)
    newDirectory = path + newFolderName
    convert(newDirectory, directoryFiles, path);

    temp = wxPython.MessageDialog( self, filesConverted, "About Sample Editor", wxPython.OK | wxPython.CENTRE)
    temp.ShowModal()
    quit()


def convert(newDir, dirFiles, filePath):
if not os.path.exists(newDir):
    os.makedirs(newDir)
for x in range(0, len(dirFiles)):
    fileName = dirFiles[x]
    fileType = fileName[(len(fileName)-10):-6]
    if jpgType == fileType or pngType == fileType:
        fileNametoReadFrom = filePath + fileName
        file = open(fileNametoReadFrom, 'rb')
        text = file.read()
        file.close()
        newFileName = filePath + newFolderName + "new " + fileName[:-6]
        file = open(newFileName, 'wb')
        file.write(text[4:-13])
        file.close()
        global filesConverted
        filesConverted = filesConverted + str(numberOfFiles) + ": Converted: " + fileNametoReadFrom + "\n"
        global numberOfFiles
        numberOfFiles = numberOfFiles + 1
filesConverted = filesConverted + "\n" + str(numberOfFiles) + " files have been placed in " + filePath + newFolderName


if __name__ == '__main__':
app = wxPython.PySimpleApp()
frame = greg(parent = None, id = -1)
frame.Show()
app.MainLoop()

This is the output I get:

Traceback (most recent call last):
    File "ConvertImagesWithInterface.py", line 1, in (module)
    File "wx\__init__.pyc", line 45, in (module)
    File "wx\_core.pyc", line 5, in (module)
    File "new.pyc", line 3, in (module)
AttributeError: 'module' object has no attribute 'Frame'

I have tried copying __init__ files and new.pyc files into different directories relevant to the (module) location, tried renaming things inside of the module, and looked at about 20 different problems other people have, but I cannot find an answer how to fix this. Anyone have any ideas?

Thanks in advance.

import wx as wxPython
import os

try:
# Python2
import Tkinter as tk
import tkFileDialog as tkfd

except ImportError:
# Python3
import tkinter as tk
import tkinter.filedialog as tkfd

newFileName = "" 
newFolderName = "new folder/"
newDirectory = "" 
path = ""
jpgType = ".jpg"
pngType = ".png"
filesConverted = ""
numberOfFiles = 0

class greg(wxPython.Frame):

def __init__(self, parent, id):
    wxPython.Frame.__init__(self, parent, id, 'Convert Images', size = (160, 110))
    panel = wxPython.Panel(self)

    button = wxPython.Button(panel, label = "exit", pos = (10, 10), size = (60, 60))
    self.Bind(wxPython.EVT_BUTTON, self.closebutton, button)
    self.Bind(wxPython.EVT_CLOSE, self.closewindow)

    button = wxPython.Button(panel, label = "convert", pos = (80, 10), size = (60, 60))
    self.Bind(wxPython.EVT_BUTTON, self.file_open, button)



def closebutton(self, event):
    self.Close(True)

def closewindow(self, event):
    self.Destroy()

def file_open(self, event):
    root = tk.Tk()
    root.withdraw() 
    path = tkfd.askdirectory(parent=root,initialdir="/",title='Please select a directory') + "/"

    directoryFiles = os.listdir(path)
    newDirectory = path + newFolderName
    convert(newDirectory, directoryFiles, path);

    temp = wxPython.MessageDialog( self, filesConverted, "About Sample Editor", wxPython.OK | wxPython.CENTRE)
    temp.ShowModal()
    quit()


def convert(newDir, dirFiles, filePath):
if not os.path.exists(newDir):
    os.makedirs(newDir)
for x in range(0, len(dirFiles)):
    fileName = dirFiles[x]
    fileType = fileName[(len(fileName)-10):-6]
    if jpgType == fileType or pngType == fileType:
        fileNametoReadFrom = filePath + fileName
        file = open(fileNametoReadFrom, 'rb')
        text = file.read()
        file.close()
        newFileName = filePath + newFolderName + "new " + fileName[:-6]
        file = open(newFileName, 'wb')
        file.write(text[4:-13])
        file.close()
        global filesConverted
        filesConverted = filesConverted + str(numberOfFiles) + ": Converted: " + fileNametoReadFrom + "\n"
        global numberOfFiles
        numberOfFiles = numberOfFiles + 1
filesConverted = filesConverted + "\n" + str(numberOfFiles) + " files have been placed in " + filePath + newFolderName


if __name__ == '__main__':
app = wxPython.PySimpleApp()
frame = greg(parent = None, id = -1)
frame.Show()
app.MainLoop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文