0

I want to use ttk as part of tkinter but I had Python 2.6 on my Mac. Therefore I went and installed Python 3.1, which has ttk come with it, and it did not overwrite the previous version. Therefore I still do not have the ability to use ttk.

Am I going about this wrong or is there something I am missing?

Ziggy
  • 99
  • 1
  • 1
  • 6
  • Did you successfully install Python3.1? Can you run it with `python3`? – unutbu May 22 '13 at 18:50
  • I opened the package and went through the install process and it installed correctly. Is there another step after that, that I am missing? – Ziggy May 22 '13 at 18:54
  • Open a terminal and type `python3` do you get an interactive prompt such as `>>> `? – unutbu May 22 '13 at 18:55
  • Yes I do get that. does this mean when I compile I use python3 instead of python? – Ziggy May 22 '13 at 18:59
  • It means when you want to *run* your script you should call it with `python3`. – unutbu May 22 '13 at 19:01
  • is there a particular reason you chose Python 3.1? 3.3 is the current release - download from [python.org](http://www.python.org/download/) – MattDMo May 22 '13 at 19:19
  • Other sources I was reading said to use Python 3.1 therefore I did not seek out a further version of it. But I could download 3.3. Are there significant differences between the 2? – Ziggy May 22 '13 at 19:25

1 Answers1

0

Try this: Save the following in test.py:

import tkinter as tk
import tkinter.ttk as tkk

class SimpleApp(object):
    def __init__(self, master, **kwargs):
        title = kwargs.pop('title')
        frame = tkk.Frame(master, **kwargs)
        frame.pack()
        self.label = tkk.Label(frame, text=title)
        self.label.pack(padx=10, pady=10)    

root = tk.Tk()
app = SimpleApp(root, title='Hello, world')
root.mainloop()

Then, at the terminal prompt, run

% python3 test.py

(To run a Python3 script, use python3. To run a Python2 script, use the python.)

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • That wont compile for me and I am trying to post a screen shot of my error. But I am new to stackoverflow and I am not sure how to do so. However these are two of the errors I am getting. app = SimpleApp(root, title='Hello, world') frame = tkk.Frame(master, **kwargs) – Ziggy May 22 '13 at 19:13
  • I need 10 reputation in order to post photos – Ziggy May 22 '13 at 19:40
  • Just copy and paste the text. That would be much better than a photo in this case anyway. – unutbu May 22 '13 at 19:52
  • Traceback (most recent call last): File "test.py", line 13, in app = SimpleApp(root, title='Hello, world') File "test.py", line 7, in __init__ frame = tkk.Frame(master, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/ttk.py", line 761, in __init__ Widget.__init__(self, master, "ttk::frame", kw) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/ttk.py", line 559, in __init__ _load_tile(master) – Ziggy May 22 '13 at 20:05
  • File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/ttk.py", line 47, in _load_tile master.tk.eval('package require tile') # TclError may be raised here _tkinter.TclError: can't find package tile – Ziggy May 22 '13 at 20:06
  • The last line of the error message says that `Tcl` can not find the `tile` package. You need to upgrade your version of Tcl. I don't have any experience with OSX, but I think [this page](http://www.python.org/getit/mac/tcltk/) might help you. – unutbu May 22 '13 at 20:18
  • I updated my `Tcl` and I am getting the same error. Unless there is a different way I should compile it now. – Ziggy May 23 '13 at 12:17
  • Your Python3 might still be linked to the old Tcl. Perhaps try reinstalling Python3 and watch to make sure it finds the new Tcl. – unutbu May 23 '13 at 12:19