【问题标题】:TKinter Does Not Work [duplicate]TKinter 不工作 [重复]
【发布时间】:2016-02-03 00:27:10
【问题描述】:

我正在开发 Python v2.x Windows 操作系统。 我注意到在安装 Python 时安装了 tcl(包括 TKinter)。

但是当我通过在 Python IDLE 上输入 'import tkinter' 来验证它时,会出现错误: “ImportError: 没有名为 tkinter 的模块”

谁能给我一些建议?谢谢。

【问题讨论】:

    标签: python-2.7 tkinter tcl


    【解决方案1】:

    在 Python2 中,

    import Tkinter
    

    在 Python3 中

    import tkinter
    

    【讨论】:

      【解决方案2】:

      Python 2.x 使用Tkinter - 见上T

      在 Python 3.x 中名称更改为 tkinter

      要同时使用这两种 Python,您可以使用

      try:
          import Tkinter as tk
      except ImportError:
          import tkinter as tk
      
      
      root = tk.Tk()
      

      【讨论】:

      • 我认为你最好先编码以支持 python 3,而不是作为后备。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多