【问题标题】:Tkinter not working on MacTkinter 无法在 Mac 上运行
【发布时间】:2013-11-26 17:36:11
【问题描述】:

我最近买了一个新的 macbook pro,我一直在用它来处理 python。 Python 已经安装好了,我的版本是 2.7.5。

但是 tkinter 根本无法处理 IDLE 或 sublime 文本!我没有收到错误或任何东西,只是当我输入我的代码时什么都没有显示!

这是我使用的示例代码:

Python 2.7.5 (default, Sep  2 2013, 05:24:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> from Tkinter import *
>>> tk = Tk()
>>> btn = Button (tk, text = "click me")
>>> btn.pack
<bound method Button.pack_configure of <Tkinter.Button instance at 0x101b4edd0>>
>>> btn.pack()

编辑:我最终只是从互联网上下载了 python idle(3.3 版)并获得了它附带的空闲,现在我只是使用它。然而,它根本没有针对视网膜进行优化,这使得使用起来非常痛苦。我现在只是使用 Windows 7 来做。不过还是谢谢你的回答

【问题讨论】:

  • 如果你把那个代码放在一个文件中,添加一个对 mainloop 的调用,然后执行这个文件,会发生什么?

标签: python macos tkinter


【解决方案1】:

奇怪:你没有导入错误,你的代码没问题。

您是否在 IDLE 或 Sublime 之外尝试过?

我从 osX 终端尝试了您的代码,它可以工作: 只要您键入 tk=Tk(),就会出现一个空窗口。 那么(第二个)按钮绑定函数实际上是在进入的时候修改了窗口。

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 2019-03-27
    • 2012-01-08
    • 2015-10-09
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多