我在 mac 上遇到了 tkinter.ttk 的问题。我正在使用 macports 和 python3.1。当我尝试使用 tkinter.ttk 时,我得到了非常古老的 gui 元素。
例如:我得到这个
而不是这个:
我使用的代码是:
from tkinter import *
from tkinter import ttk
root = Tk()
button = ttk.Button(root, text="Hello World").grid()
root.mainloop()
我很乐意从我的计算机中提供回答这个问题所需的任何信息。由于我是新手程序员,请告诉我在哪里可以找到上述信息。
我有一台安装了 Snow Leopard 的 Macbook 5,2。任何帮助,将不胜感激。
谢谢,马伦
问题更新:
我按照schlenk 的建议安装了tk @8.5.9_0+quartz ,只是为了得到这个错误:
TclMacOSXNotifierAddRunLoopMode: Tcl not built with CoreFoundation support Abort trap
我使用来自https://trac.macports.org/ticket/22954的补丁修复了这个错误。我按照信中的说明进行操作(它们是):
$ cd /opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/tcl
$ sudo patch < ~/Downloads/tcl.2.patch
$ sudo port install tcl
这产生了一个新错误,即:
Traceback (most recent call last):
File "hello.py", line 5, in <module>
root = Tk()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 1632, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable tk.tcl in the following directories:
/opt/local/lib/tcl8.5/tk8.5 /opt/local/lib/tcl8.5/tk8.5/Resources/Scripts /opt/local/lib/tk8.5 /opt/local/lib/tk8.5/Resources/Scripts /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/lib/tk8.5 /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/lib/tk8.5/Resources/Scripts /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/lib/tk8.5 /opt/local/Library/Frameworks/Python.framework/Versions/3.1/Resources/Python.app/Contents/library
/opt/local/lib/tk8.5/tk.tcl: version conflict for package "Tk": have 8.5.7, need exactly 8.5.9
version conflict for package "Tk": have 8.5.7, need exactly 8.5.9
while executing
"package require -exact Tk 8.5.9"
(file "/opt/local/lib/tk8.5/tk.tcl" line 20)
invoked from within
"source /opt/local/lib/tk8.5/tk.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $file]"
This probably means that tk wasn't installed properly.