ImportError:无法从“操作员”导入名称“ itemgetter”

时间:2019-04-20 13:11:00

标签: python-3.x tkinter import

为我的问题提供帮助,我制作了一个名为'percobaan.py'的文件,并使用cmd运行了该文件,但出现了一些错误。错误说ImportError: cannot import name 'itemgetter' from 'operator',但是如果我在python IDLE中运行我的代码,该代码将运行而没有任何错误。

我的代码:

import tkinter

def msg():
    print("i'm learning tkinter built in")

root = tkinter.Tk()

label = tkinter.Label(root, text='welcome to the tkinter built in project')
label.pack()

label2 = tkinter.Label(root,text='choose your favorite programming languange',
justify=tkinter.CENTER, 
padx=20)
label2.pack()

tkinter.Radiobutton(root, text='python',padx=20, value= 1).pack(anchor=tkinter.N)
tkinter.Radiobutton(root, text='Javascript',padx=20, value= 2).pack(anchor=tkinter.N)
tkinter.Radiobutton(root, text='C++',padx=20, value= 3).pack(anchor=tkinter.N)
tkinter.Radiobutton(root, text='C',padx=20, value= 4).pack(anchor=tkinter.N)


frame = tkinter.Frame(root)
frame.pack()

button = tkinter.Button(frame, text='quit',fg='black',command=quit)
button.pack(side=tkinter.LEFT)

slogan = tkinter.Button(frame, text='see the message',command=msg)
slogan.pack(side=tkinter.RIGHT)

root.mainloop()

错误提示:

Traceback (most recent call last):
File "GUI.py", line 1, in <module>
import tkinter
File "C:\Users\khairunnisa\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 39, in <module>
import re
File "C:\Users\khairunnisa\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 125, in <module>
import functools
File "C:\Users\khairunnisa\AppData\Local\Programs\Python\Python37-32\lib\functools.py", line 21, in <module>
from collections import namedtuple
File "C:\Users\khairunnisa\AppData\Local\Programs\Python\Python37-32\lib\collections\__init__.py", line 21, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter' from 'operator' (D:\JOB\__python\exercise_oop\GUI\operator.py)

我已经尝试过多次运行此代码,并且这些软件包已经安装在我的PC上,但结果仍然没有。 知道为什么吗?

0 个答案:

没有答案