Saf*_*ron 2 python macos tkinter tix python-3.x
一位朋友给我发了一些Tkinter/Tix代码,但它适用于Python 2:
from Tkinter import *
import Tix
import ScrolledText
Run Code Online (Sandbox Code Playgroud)
我有Python 3,我没有Tix安装,程序崩溃.经过一番搜索后,我将代码更改为:
from tkinter import *
from tkinter import tix
from tkinter import scrolledtext
Run Code Online (Sandbox Code Playgroud)
这就是我在互联网上找到的东西.我不知道这是不是一个正确的方法.但代码仍然没有运行它崩溃
root = tix.Tk()
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/tkinter/tix.py, line 221, in __init__
self.tk.eval('package require Tix')
_tkinter.TclError: can't find package Tix
Run Code Online (Sandbox Code Playgroud)
我想知道如何正确修改代码以使其运行以及如何安装Tix.
原始形式的整个代码:http: //pastebin.com/JCqhNSRR
我在这里测试了这个问题(Ubuntu 12.04.5)并且遇到了同样的错误.浏览网页发现了有关此功能错误的争论.这是我找到解决方案的转录部分:
我在Ubuntu 13.04上,当我看到这个错误时,我安装了tix-dev包,一切正常.我相信它在OSX上同样简单,但我不知道它.另外,请确保您运行的是Python 3.3,因为这是我正在开发/测试/使用GUI的唯一版本.
我安装了tix-dev(apt-get install tix-dev)并使用Python 2.7.3和Python 3.2.3进行了测试并且正常工作.
tkinter在Python 3.3.3和OSX 10.9.5Tix中的2.7.5中进行的测试与使用ActiveTcl 8.6.3.1的 Ubuntu具有相同的问题.
问题出在Tcl lib Tix上.解决方案是使用64位支持重新编译lib.
我用来编译的标志是:
$ ./configure --enable-64bit --enable-threads --enable-framework --enable-aqua --enable-corefoundation
Run Code Online (Sandbox Code Playgroud)
为了确保编译到64位平台运行以下命令
$ lipo -info libTix8.4.3.dylib
Non-fat file: libTix8.4.3.dylib is architecture: x86_64
Run Code Online (Sandbox Code Playgroud)
编译完成后,将libTix8.4.3.dylib复制到由Tcl/Tk包安装的libTix路径中.
通常路径是 /Library/Tcl/teapot/package/macosx10.5-i386-x86_64/lib/Tix8.4.3/libTix8.4.3.dylib
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import tix
>>> root = tix.Tk()
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5291 次 |
| 最近记录: |