Python3.5安装tkinter

系统环境:CentOS 6.7 64bit

1) yum -y install tkinter tcl-devel tk-devel

安装完以后的库以及头文件为:

[root@localhost lib]# ll /usr/lib64/libtk*
lrwxrwxrwx. 1 root root      11 Dec 12 06:28 /usr/lib64/libtk.so -> libtk8.5.so

[root@localhost lib]# ll /usr/lib64/libtcl.so
lrwxrwxrwx. 1 root root 12 Dec 12 06:28 /usr/lib64/libtcl.so -> libtcl8.5.so

[root@localhost include]# ll /usr/include/tcl.h
-rw-r--r--. 1 root root 87115 Nov 11  2010 /usr/include/tcl.h
[root@localhost include]# ll /usr/include/tk.h
-rw-r--r--. 1 root root 57479 Nov 11  2010 /usr/include/tk.h

2) 修改Python-3.5.0/Modules/Setup.dist

# The _tkinter module.
#
# The command for _tkinter is long and site specific.  Please
# uncomment and/or edit those parts as indicated.  If you don't have a
# specific extension (e.g. Tix or BLT), leave the corresponding line
# commented out.  (Leave the trailing backslashes in!  If you
# experience strange errors, you may want to join all uncommented
# lines and remove the backslashes -- the backslash interpretation is
# done by the shell's "read" command and it may not be implemented on
# every system.

将下面几句的注释去掉:

# *** 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/lib64 \
# *** Uncomment and edit to reflect where your Tcl/Tk headers are:
-I/usr/include \

# *** Uncomment and edit to reflect your Tcl/Tk versions:
-ltk8.5 -ltcl8.5 \

# *** Always uncomment this; X11 libraries to link with:
-lX11

3)重新编译Python3.5

/configure

make

make install

4) 验证

[root@localhost Python-3.5.0]# python
Python 3.5.0 (default, Dec 12 2018, 06:47:47)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>

如果是在windows或者图形化的linux下执行python -m tkinter,可以弹出tk窗口。
 

发布了9 篇原创文章 · 获赞 459 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/songhait/article/details/96161039