How to pip or easy_install tkinter on Windows

前端 未结 12 751
你的背包
你的背包 2020-11-28 22:31

My Idle is throwing errors that and says tkinter can\'t be imported.

Is there a simple way to install tkinter via pip or

相关标签:
12条回答
  • 2020-11-28 22:47

    The Tkinter library is built-in with every Python installation. And since you are on Windows, I believe you installed Python through the binaries on their website?

    If so, Then most probably you are typing the command wrong. It should be:

    import Tkinter as tk
    

    Note the capital T at the beginning of Tkinter.

    For Python 3,

    import tkinter as tk
    
    0 讨论(0)
  • 2020-11-28 22:50

    Inside cmd, run command pip install tk and Tkinter should install.

    0 讨论(0)
  • 2020-11-28 22:53

    if your using python 3.4.1 just write this line from tkinter import * this will put everything in the module into the default namespace of your program. in fact instead of referring to say a button like tkinter.Button you just type Button

    0 讨论(0)
  • 2020-11-28 22:56

    When installing make sure that under Tcl/Tk you select Will be installed on hard drive. If it is installing with a cross at the left then Tkinter will not be installed.

    The same goes for Python 3:

    0 讨论(0)
  • 2020-11-28 22:56

    Had the same problem in Linux. This solved it. (I'm on Debian 9 derived Bunsen Helium)

    $ sudo apt-get install python3-tk

    0 讨论(0)
  • 2020-11-28 23:02

    I'm posting as the top answer requotes the documentation which I didn't find useful.

    tkinter comes packaged with python install on windows IFF you select it during the install window.

    The solution is to repair the installation (via uninstall GUI is fine), and select to install tk this time. You may need to point at or redownload the binary in this process. Downloading directly from activestate did not work for me.

    This is a common problem people have on windows as it's easy to not want to install TCL/TK if you don't know what it is, but Matplotlib etc require it.

    0 讨论(0)
提交回复
热议问题