gpt4 book ai didi

user-interface - 如何使我的 ttk 小部件看起来很现代?

转载 作者:行者123 更新时间:2023-12-04 06:39:49 26 4
gpt4 key购买 nike

我在 Mac 上遇到 tkinter.ttk 问题。我正在使用 macports 和 python3.1。当我尝试使用 tkinter.ttk 时,我得到了非常古老的 gui 元素。

例如:我明白了
enter image description here
而不是这个:
enter image description here

我使用的代码是:

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.

最佳答案

问题可能出在 macports 上。您可以使用三个版本的 Tk 作为 ttk 的基础。屏幕截图看起来很像旧的 X11 Tk,而不是基于 aqua 的 Tk。1. Tk 通过 X11。2. Tk 使用 Carbon 'windowingsystem -aqua' 编译3.用Cocoa编译的tk

因此,您应该尝试通过 macports 构建一个 Tk 变体“quartz”,或者您应该获得一些已经构建了正确版本的预构建版本(例如 ActiveStates)。

所以尝试:

sudo port build tk @8.5.9+quartz

查看此处的教程以获得更多指导: http://www.tkdocs.com/tutorial/install.html#installmac

关于user-interface - 如何使我的 ttk 小部件看起来很现代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5073773/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com