为什么我无法运行 .exe 转换后的 wxPython 文件?属性错误
这是我得到的输出:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论