tkinter模块问题

tkinter模块问题


Python3找不到tkinter模块:

解决一:

安装tkinter模块:
sudo apt-get update 先更新
sudo apt-get python3-tk

解决二:

tkinter是由tcl和tk两个部分组成:
先下载这两个东西
下载地址:https://www.tcl.tk/software/tcltk/download.html

解压tar -zxvf

先进去tcl中的unix文件夹进行安装命令

    ./configure
            make
            sudo make install

然后进入tk中的unix文件夹进行安装命令
命令如上

如果安装tcl的时候出现类似x11/xlib.h:没有那个文件或目录
还需要多一步,需要安装sudo apt-get install libx11.dev

输入wish回车 会出现一个界面,不用管,切换到命令窗口

输入info tclversion 和puts $tk_version查看版本。 (版本号后面有需要)

进入Python解压包的目录下,不是安装的目录。是没有编译的源代码目录

找到Setup.dist文件

在Modules/Setup.dist

找到以下这段话

            # *** Always uncomment this (leave the leading underscore in!):
             _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \           #去掉注释
            # *** Uncomment and edit to reflect where your Tcl/Tk libraries are:
                -L/usr/local/lib \                                      #去掉注释
            # *** Uncomment and edit to reflect where your Tcl/Tk headers are:
            #   -I/usr/local/include \
            # *** Uncomment and edit to reflect where your X11 header files are:
                -I/usr/X11R6/include \                                  #去掉注释
            # *** Or uncomment this for Solaris:
            #   -I/usr/openwin/include \
            # *** Uncomment and edit for Tix extension only:
            #   -DWITH_TIX -ltix8.1.8.2 \
            # *** Uncomment and edit for BLT extension only:
            #   -DWITH_BLT -I/usr/local/blt/blt8.0-unoff/include -lBLT8.0 \
            # *** Uncomment and edit for PIL (TkImaging) extension only:
            #     (See http://www.pythonware.com/products/pil/ for more info)
            #   -DWITH_PIL -I../Extensions/Imaging/libImaging  tkImaging.c \
            # *** Uncomment and edit for TOGL extension only:
            #   -DWITH_TOGL togl.c \
            # *** Uncomment and edit to reflect your Tcl/Tk versions:
                -ltk8.2 -ltcl8.2 \                                  #去掉注释,并改成相应的版本,如我的是8.6,就写-ltk8.6 -ltcl8.6 \
            # *** Uncomment and edit to reflect where your X11 libraries are:
            #   -L/usr/X11R6/lib \
            # *** Or uncomment this for Solaris:
            #   -L/usr/openwin/lib \
            # *** Uncomment these for TOGL extension only:
            #   -lGL -lGLU -lXext -lXmu \
            # *** Uncomment for AIX:
            #   -lld \
            # *** Always uncomment this; X11 libraries to link with:
                -lX11                                               #去掉注释

sudo apt-get install libreadline-dev 这个必须安装,因为不安装,在Python交互中上下左右移动无法成功.

重新编译和安装Python3.x

等待几分钟。安装成功后,输入python3

接着输入import tkinter

如果没有任何提示,那就OK了,没有消息就是最好的消息。

解决三:

如果是centos或fedora,可以执行 sudo dnf install python3-tkinter

推荐用解决二

猜你喜欢

转载自blog.csdn.net/qq_31403321/article/details/78672215
今日推荐