为什么说没有名为tkinter的模块?

时间:2015-12-01 07:03:21

标签: python tkinter

美好的一天。 我在笔记本电脑上安装了pyhton 2和python 3。我在编写代码时使用python 3解释器。这是我的代码。

#! /usr/bin/python3

from tkinter import *

root = Tk()

theLabel = Label(root, text ="This is too easy")
theLabel.pack()

root.mainloop()

但是当我双击保存文件图标时。它会说没有模块名称tkinter。有人可以帮助我吗?

2 个答案:

答案 0 :(得分:3)

python 2和python 3以不同的方式使用PYTHONPATH

  

注意: Tkinter已在Python 3中重命名为tkinter.2to3工具会在将源代码转换为Python 3时自动调整导入。

以上几行来自python文档。不确定python是否使用python 2或python 3加载tkinter。可能是内部try: import tkinter as tk except ImportError: import Tkinter as tk 弄乱 相反,试试这个,

virualenv

注意:在这些使用相同模块的多个版本的情况下,请尝试使用 func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) { if challenge.protectionSpace.authenticationMethod == (NSURLAuthenticationMethodServerTrust) { let serverTrust:SecTrustRef = challenge.protectionSpace.serverTrust! let certificate: SecCertificateRef = SecTrustGetCertificateAtIndex(serverTrust, 0)! let remoteCertificateData = CFBridgingRetain(SecCertificateCopyData(certificate))! let cerPath: String = NSBundle.mainBundle().pathForResource("xyz.com", ofType: "cer")! let localCertificateData = NSData(contentsOfFile:cerPath)! if (remoteCertificateData.isEqualToData(localCertificateData) == true) { let credential:NSURLCredential = NSURLCredential(forTrust: serverTrust) challenge.sender?.useCredential(credential, forAuthenticationChallenge: challenge) completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)) } else { completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil) } } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate { let path: String = NSBundle.mainBundle().pathForResource("client", ofType: "p12")! let PKCS12Data = NSData(contentsOfFile:path)! let identityAndTrust:IdentityAndTrust = self.extractIdentity(PKCS12Data); let urlCredential:NSURLCredential = NSURLCredential( identity: identityAndTrust.identityRef, certificates: identityAndTrust.certArray as? [AnyObject], persistence: NSURLCredentialPersistence.ForSession); completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, urlCredential); } else { completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil); } }

Virtual Env

答案 1 :(得分:2)

在使用之前需要检查模块名称或包名称,执行此操作

from Tkinter import *
相关问题