Tkinter Python3 中,我明明给他定义了str,可他还说Nonetype,这是怎么回事?

以下是代码:——————————————————————————————————————importtkinterastkimporttkinterasTkimports... 以下是代码:
——————————————————————————————————————
import tkinter as tk
import tkinter as Tk
import sys
from tkinter import *
from tkinter import ttk
root=tk.Tk()
root.title("翻译器 1.0Beta 汉化版")
root.geometry('300x300')
root.resizable(0,0)
chinese_ORPMLZ={"你好":"eic","再见":"cie","对不起":"ice","没关系":"eci","我":"M","你":"A","她":"A_","它":"A-_","他":"A-","蟒蛇":"PN","命令":"CO","代码":"VW","文件":"F","视图":"WV","复习":"RW","退出":"Qz","中文":"CN","英语":"CE","数学":"MH","爪哇":"JV","我的世界":"MCT","系统":"SM","写":"WVW"}

def chinesemode():
chinesewin=tk.Tk()
chinesewin.title("中文模式")
chinesewin.geometry('500x300')
chinesewin.resizable(0,0)
chineseent=tk.Entry(chinesewin).pack(side='right').get()
chineselab=tk.Label(chinesewin,text=" 请输入中文:").pack(side='left')
def 翻译():
翻译win=tk.Tk()
翻译win.title("翻译内容")
翻译win.geometry('300x300')
翻译win.resizable(0,0)
try:
翻译lab=tk.Label(翻译win,text=chinese_ORPMLZ[str(chineseent)])
except KeyError:
Error=tk.Tk()
Error.title("Error1")
Error.geometry('300x300')
Error.resizable(0,0)
Errorbut1=tk.Button(Error,text='close',command=lambda:Error.distroy()).pack()
chinesebut=ttk.Button(chinesewin,text="翻译",command=翻译).pack(side='bottom')
chinesewin.mainloop()
chinesech=tk.Button(root,text="中文",command=chinesemode).pack()
root.mainloop()
print(type(chineseent.get()))
————————————————————————————————————
以下是输出(报错):
————————————————————————————————————
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/Volumes/我才不是硬盘(D) /Python/点子/Tkinter/fanyiqi.py", line 17, in chinesemode
chineseent=tk.Entry(chinesewin).pack(side='right').get()
AttributeError: 'NoneType' object has no attribute 'get'
展开
 我来答
哈哈呵呵你好7
2019-03-21 · TA获得超过1626个赞
知道大有可为答主
回答量:2238
采纳率:79%
帮助的人:245万
展开全部

你好,那个Nonetyp是说你输入框当前的信息是Nonetyp。你原来的代码是在你创建那个输入框的时候直接读入输入的信息,所以你tk.Entry(chinesewin).pack(side='right').get()就会直接得到一个None的输入。下面是我帮你修改好的代码,可以跑的。你试试好了。

import tkinter as tk
import tkinter as Tk
import sys
from tkinter import *
from tkinter import ttk
from functools import partial
root=tk.Tk()
root.title("翻译器 1.0Beta 汉化版")
root.geometry('300x300')
root.resizable(0,0)
chinese_ORPMLZ={"你好":"eic","再见":"cie","对不起":"ice","没关系":"eci","我":"M","你":"A","她":"A_","它":"A-_","他":"A-","蟒蛇":"PN","命令":"CO","代码":"VW","文件":"F","视图":"WV","复习":"RW","退出":"Qz","中文":"CN","英语":"CE","数学":"MH","爪哇":"JV","我的世界":"MCT","系统":"SM","写":"WVW"}
def chinesemode():
    chinesewin=tk.Tk()
    chinesewin.title("中文模式")
    chinesewin.geometry('500x300')
    chinesewin.resizable(0,0)
    chineselab=tk.Label(chinesewin,text=" 请输入中文:").pack(side='left')
    chineseent=tk.Entry(chinesewin)
    chinesebut=ttk.Button(chinesewin,text="翻译",command=partial(transfer, chineseent)).pack(side='bottom')
    chineseent.pack(side='right')
    chinesewin.mainloop()
#def on_button(self):
#    print(self.entry.get())    
    
def transfer(chineseent):
    inputStr = chineseent.get()
    if inputStr in chinese_ORPMLZ:
        win=tk.Tk()
        win.title("翻译结果")
        win.geometry('300x300')
        win.resizable(0,0)
        print (chinese_ORPMLZ[str(inputStr)])
        translab=tk.Label(win,text=chinese_ORPMLZ[str(inputStr)]).pack()
    else:
        Error=tk.Tk()
        Error.title("Error1")
        Error.geometry('300x300')
        Error.resizable(0,0)
        Errorbut1=tk.Button(Error,text='close',command=lambda:Error.distroy()).pack()
chinesech=tk.Button(root,text="中文",command=chinesemode).pack()
root.mainloop()
#print(type(chineseent.get()))
zxszx4
2019-03-20 · TA获得超过511个赞
知道小有建树答主
回答量:732
采纳率:42%
帮助的人:210万
展开全部
我猜是tk.Entry(chinesewin).pack(side='right')没有获取到数据
追问
我输了‘’啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式