为什么提示找不到images模块
Traceback (most recent call last):File "E:\Python\installation path\Pythondebug\wx.Menu.py", line 3, in <module>
import images
ModuleNotFoundError: No module named 'images'
遇到这样的报错了!请问应该怎么样解决
#!/usr/bin/env python
import wx
import images
class ToolbarFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Toolbars',
size=(300,200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar() #1 创建状态栏
toolbar = self.CreateToolBar() #2 创建工具栏
toolbar.AddTool(wx.NewId(),images.getNewBitmap(),
'New',"Long help for 'New'") #3 给工具栏增加一个工具
toolbar.Realize() #4 准备显示工具栏
menuBar = wx.MenuBar() # 创建菜单栏
#创建两个菜单
menu1 = wx.Menu()
menuBar.Append(menu1,'&File')
menu2 = wx.Menu()
#6 创建菜单的项目
menu2.Append(wx.NewId(),'&Copy','Copy in status bar')
menu2.Append(wx.NewId(),'&Cut','')
menu2.Append(wx.NewId(),'&Paste','')
menu2.AppendSeparator()
menu2.Append(wx.NewId(),'&Options...','Display Options')
menuBar.Append(menu2,'&Edit') # 在菜单栏上附上菜单
self.SetMenuBar(menuBar) # 在框架上附上菜单栏
if __name__ == '__main__':
app = wx.App()
frame = ToolbarFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()
运行这个代码 A.Lyapunov 发表于 2020-7-24 17:33
运行这个代码
你确定 images 模块安装了吗? A.Lyapunov 发表于 2020-7-24 17:33
运行这个代码
提示没有名为 images 这个模块,用 pip 安装试试 Twilight6 发表于 2020-7-24 17:34
你确定 images 模块安装了吗?
请问应该怎么样安装,pip安装报错了 zltzlt 发表于 2020-7-24 17:35
提示没有名为 images 这个模块,用 pip 安装试试
E: \Python\installation path\Scripts>pip install images
ERROR: Could not find a version that satisfies the requirement images ( from versi ons: none )
ERROR: No matching di stribution found for images
报错了 A.Lyapunov 发表于 2020-7-24 17:39
E: \Python\installation path\Scripts>pip install images
ERROR: Could not find a version that sati ...
提示没有名叫 images 的第三方库 A.Lyapunov 发表于 2020-7-24 17:37
请问应该怎么样安装,pip安装报错了
我去官方搜索了没有找到这种库:https://pypi.org/search/?q=images
本帖最后由 liuzhengyuan 于 2020-7-24 17:50 编辑
你是说 PIL 的 image 吗?
先
pip install Pillow
然后
from PIL import Image liuzhengyuan 发表于 2020-7-24 17:44
你是说 PIL 的 image 吗?
先
是 Pillow 不是 pillow 哦 Twilight6 发表于 2020-7-24 17:49
是 Pillow 不是 pillow 哦
感谢指出 liuzhengyuan 发表于 2020-7-24 17:44
你是说 PIL 的 image 吗?
先
我也不清楚,是wxPython in Action 这本书中的一个例子,它上面不是image,而是images Twilight6 发表于 2020-7-24 17:49
是 Pillow 不是 pillow 哦
大写小写都无所谓
E:\>pip install pillow
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pillow in e:\program\python 3.8.0\lib\site-packages (6.2.1) A.Lyapunov 发表于 2020-7-24 17:53
我也不清楚,是wxPython in Action 这本书中的一个例子,它上面不是image,而是images
有可能是作者自己写的一个模块,你看看书上有没有关于 新建自定义模块 的例子? zltzlt 发表于 2020-7-24 17:55
大写小写都无所谓
{:10_250:} 哦哦,我 Python 学久了,一直记得严格区分大小写了 liuzhengyuan 发表于 2020-7-24 17:56
有可能是作者自己写的一个模块,你看看书上有没有关于 新建自定义模块 的例子?
没有找到。。 A.Lyapunov 发表于 2020-7-24 18:11
没有找到。。
代码改成这样:
#!/usr/bin/env python
import wx
import wx.py.images as images
class ToolbarFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Toolbars',
size=(300, 200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar()# 1 创建状态栏
toolbar = self.CreateToolBar()# 2 创建工具栏
toolbar.AddTool(wx.NewId(), images.getNewBitmap(),
'New', "Long help for 'New'")# 3 给工具栏增加一个工具
toolbar.Realize()# 4 准备显示工具栏
menuBar = wx.MenuBar()# 创建菜单栏
# 创建两个菜单
menu1 = wx.Menu()
menuBar.Append(menu1, '&File')
menu2 = wx.Menu()
# 6 创建菜单的项目
menu2.Append(wx.NewId(), '&Copy', 'Copy in status bar')
menu2.Append(wx.NewId(), '&Cut', '')
menu2.Append(wx.NewId(), '&Paste', '')
menu2.AppendSeparator()
menu2.Append(wx.NewId(), '&Options...', 'Display Options')
menuBar.Append(menu2, '&Edit')# 在菜单栏上附上菜单
self.SetMenuBar(menuBar)# 在框架上附上菜单栏
if __name__ == '__main__':
app = wx.App()
frame = ToolbarFrame(parent=None, id=-1)
frame.Show()
app.MainLoop() Twilight6 发表于 2020-7-24 18:28
代码改成这样:
Warning (from warnings module):
File "E:\Python\installation path\Pythondebug\wx.Menu.py", line 14
toolbar.AddTool(wx.NewId(), images.getNewBitmap(),
DeprecationWarning: NewId() is deprecated
Traceback (most recent call last):
File "E:\Python\installation path\Pythondebug\wx.Menu.py", line 34, in <module>
frame = ToolbarFrame(parent=None, id=-1)
File "E:\Python\installation path\Pythondebug\wx.Menu.py", line 14, in __init__
toolbar.AddTool(wx.NewId(), images.getNewBitmap(),
AttributeError: module 'wx.py.images' has no attribute 'getNewBitmap'
报错了 Warning (from warnings module):
File "E:\Python\installation path\Pythondebug\wx.Menu.py", line 26
menu2.Append(wx.NewId(),'&Options...','Display Options')
DeprecationWarning: NewId() is deprecated
NewId()已经弃用了,那有什么函数来代替吗 A.Lyapunov 发表于 2020-7-24 18:49
Warning (from warnings module):
File "E:\Python\installation path\Pythondebug\wx.Menu.py", line ...
不太清楚了,那就帮不到你了
页:
[1]