2

A friend sent me some Tkinter/Tix code, but it was for Python 2:

from Tkinter import * 
import Tix
import ScrolledText   

I have Python 3, I have no Tix installed, and program crashes. After some searching I've changed the code to:

from tkinter import * 
from tkinter import tix
from tkinter import scrolledtext  

Thats what I found on the internet. I have no idea if this is a right approach. But code still does no run it crashes on

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

I would like to know how to modify the code correctly to make it run and how to install Tix.

The whole code in original form: http://pastebin.com/JCqhNSRR

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Safiron
  • 883
  • 4
  • 11
  • 30
  • I am sure you have already seen this, but if not, have you tried the steps here?: https://docs.python.org/3.1/library/tkinter.tix.html#using-tix – elethan Mar 22 '15 at 20:45
  • 1
    I've deleted my answer since it clearly wasn't going to work. I'll just quickly note the main content (since the links might be slightly useful as a starting point): http://stackoverflow.com/questions/14253524/trouble-finding-the-default-packages-shipped-with-python-on-snow-leopard details an identical problem. They recommend installing Tcl and Tk from one of the links at https://www.python.org/download/mac/tcltk/ (depending on which version of OS X) – DavidW Mar 27 '15 at 14:33
  • 2
    Tix might be installable with ActiveTCL using `teacup`. Unfortunately it looks like it's only available for 32 bit versions currently (https://mail.python.org/pipermail/python-bugs-list/2015-January/260042.html) – DavidW Mar 27 '15 at 14:33
  • @DavidW Yes, thanks for the effort. I hope they (ActiveState) or whoever, restart and support this project again. Or at least I hope `ttk` has some more widgets in next releases. – nbro Mar 27 '15 at 14:40
  • 1
    I have one further thought on the subject. I haven't/can't try it, so apologies if it's a dead end. I think Tk on Mac has split into X11 and Aqua, with most people supporting Aqua. Tix looks to have never updated beyond X11, and so probably can't be included in most distributions. If you're prepared to build it (and Tk) yourself, I suspect the X11 version would probably still work. You'd obviously need to run an X server. Have a look at http://core.tcl.tk/tk/artifact/36e1d82a48234014 and `--enable-aqua` to try to get an idea about how to do that. – DavidW Mar 27 '15 at 21:40

3 Answers3

7

I've tested this issue here (Ubuntu 12.04.5) and have got same error. Browsing over web found a debate about this feature's error. Here's a transcription part where I found the solution:

I am on Ubuntu 13.04 and when I see this error, I install tix-dev package and everything just works. I'd believe its similarly simple on OSX, but I have no clue about it. Also, make sure you're running Python 3.3 as that's the only version I'm developing/testing/using the GUI with.

I installed tix-dev (apt-get install tix-dev) and have tested with Python 2.7.3 and Python 3.2.3 and works.

Tests importing tkinter in Python 3.3.3 and Tix in 2.7.5 in OSX 10.9.5 have same issues with Ubuntu using ActiveTcl 8.6.3.1.

The problem is with Tcl lib Tix. The solution is to recompile the lib with 64 bit support.

The flags I used to compile were:

$ ./configure --enable-64bit --enable-threads --enable-framework --enable-aqua --enable-corefoundation

To enssure the were compiled to 64 bits platform run the following command

$ lipo -info libTix8.4.3.dylib
Non-fat file: libTix8.4.3.dylib is architecture: x86_64

After compile, copy the libTix8.4.3.dylib to path of libTix were installed by Tcl/Tk package.

Usually the path is /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()
>>> 
Mauro Baraldi
  • 6,346
  • 2
  • 32
  • 43
  • 2
    Mauro is correct that the current ActiveState OS X teapot version of Tix is only built for Intel 32-bit; it should be a universal 32-bit/64-bit version. That seems to be due to a bug in how ActiveState builds it. Rather than building your own 64-bit version of Tix, another potential option is to just run Python 3.4 in 32-bit mode, assuming you don't have any 64-bit-only dependencies. If you are using a python.org 3.4, just run `python3.4-32`. But be aware that you may find problems with using Tix with current OS X Tk's. I tried running some demos and they didn't work well. – Ned Deily Mar 31 '15 at 20:20
  • Also note that you may need to first install or update the Tix extension. You can use the ActiveTcl `teacup` command to do so: `sudo teacup update` and `sudo teacup install Tix`. – Ned Deily Mar 31 '15 at 20:26
1

I has the same problem with Python 3.8 and pyinstaller 3.0

Solved by copying folder tix8.4.3 located in YOUR_PYTHON_INSTALL_PATH\Python38-32\Scripts\dist to the dist folder.

Aman Kejriwal
  • 521
  • 1
  • 7
  • 28
0

You should import library using the syntax from tkinter.tix import Tk, ScrolledText instead of from tkinter import scrolledtext.

john-hen
  • 4,410
  • 2
  • 23
  • 40