出现非英文字符时出错

时间:2018-02-18 09:03:50

标签: python python-2.7 tkinter

当用户插入非英文字符时,脚本会因错误而停止。

# -*- coding: utf-8 -*-
from Tkinter import *
wnd = Tk()
name_A = Entry(wnd)
name_A.pack()
def AAAA1():
     A1 = name_A.get()
     with open("file_name.TXT", 'w') as f:
        f.write(A1)
Button(wnd, text="GO", command=AAAA1).pack()
wnd.mainloop()

UnicodeDecodeError:'ascii'编解码器无法解码位置0中的字节0xd7:序数不在范围内(128

0 个答案:

没有答案