2016-05-17 6 views
0

私はクラスをスキップすることができる回数を教えるためのコードの開発を進めています。tkinterコールバックエラーメッセージのまれな例外

Exception in Tkinter callback 
Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__ 
    return self.func(*args) 
    File "/Users.py", line 52, in inicio 
    for line in improt: 
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/encodings/ascii.py", line 26, in decode 
    return codecs.ascii_decode(input, self.errors)[0] 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 25: ordinal not in range(128) 

私はすでにmtTkinterをインポートしようとしたが、プログラムがそれを認識していなかった。常に表示されている具体的な間違いがあるのでそれは動作しません。間違いは、tkinterが間違った数のargを取得していると言います。エラーの原因となった行は次のとおりです。

for line in importar: 
     lista.append(line) 

しかし、これは正しい数の引数のようですが、どうなっていますか?

また、プログラムを正常に動作させるのに奇妙な間違いがあります。

私は自分のコードを入れて、動作するかどうかを確認できます。

from tkinter import* 
import math 
import tkinter.filedialog 
import traceback 
import sys 

ventana=Tk() 
ventana.title("Este programa le dice cuantas veces mas puede faltar de ausencias 1, 2 y 3") 
ventana.geometry("1000x1000") 

lista=[] 

clas=Label(ventana, text="Si tu materia es Tecno, Frances o Edufis, escribela tal cual en el cuadro").place(x=50,y=90) 
classe=Entry(ventana) 
classe.place(x=50,y=110) 

segu=Label(ventana, text="Si tu materia es Español o Actualidad, escribela tal cual en el cuadro").place(x=50,y=140) 
segun=Entry(ventana) 
segun.place(x=50,y=160) 

tercis=Label(ventana, text="Si tu materia es Qui, Math, Ingles o Filosofia, escribela tal cual en el cuadro").place(x=50,y=190) 
terce=Entry(ventana) 
terce.place(x=50,y=220) 


a=Label(ventana, text="¿Cuantas veces ha faltado por ausencias o retardos 1?").place(x=50,y=250) 
aa=Entry(ventana) 
aa.place(x=50,y=270) 

b=Label(ventana, text="¿Cuantas veces ha faltado por ausencias o retardos 2?").place(x=50,y=300) 
bb=Entry(ventana) 
bb.place(x=50,y=320) 

c=Label(ventana, text="¿Cuantas veces ha faltado por ausencias o retardos 3?").place(x=50,y=350) 
cc=Entry(ventana) 
cc.place(x=50,y=380) 


def inicio(): 
    global lista 
    global classe 
    global segu 
    global tercis 
    global aa 
    global bb 
    global cc 


    clases=(Entry.get(classe)) 
    materias = filedialog.askopenfilename(filetypes=(("Archivo de texto","*.txt"),("Cualquier archivo","*.*"))) 
    improt = open(materias,"r") 

    for line in improt: 
     lista.append(line) 

    if clases== Tecno: 
     Tecno= lista(0) 

    if clases== Frances: 
     Frances= lista(1) 

    if clases== Edufis: 
     Edufis= lista(2) 

    for i in range (0,2): 
     total=70 


    AM= (total*15)/100 

    A=(Entry.get(aa)) 

    if A<AM: 
     res= AM-A 

     print("le quedan ", res, " ausencias o retardos 1") 

    if A==AM: 

     print("No puede tener mas ausencias o retardos 1") 

    if A>AM: 

     print("Ya se paso del maximo de ausencias o retardos 1") 


    segunda=(Entry.get(segun)) 

    if segun== Español: 
     Español= lista(3) 

    if segun== Actualidad: 
     Actualidad= lista(4) 

    for i in range(3,4): 
     totala=140 

    BM= (totala*15)/100 

    B=(Entry.get(bb)) 

    if B<AM: 
     tes= AM-B 

     print("le quedan ", tes, " ausencias o retardos 2") 

    if B==AM: 

     print("No puede tener mas ausencias o retardos 2") 

    if B>AM: 

     print("Ya se paso del maximo de ausencias o retardos 2") 

    tercera=(Entry.get(terce)) 

    if terce== Qui: 
     Qui= lista(5) 

    if terce== Math: 
     Math= lista(6) 

    if terce== Ingles: 
     Ingles= lista(7) 

    if terce== Filo: 
     Filo= lista(8) 

    for i in range (5,8): 
     totale=175 

    CM= (totale*15)/100 

    C=(Entry.get(cc)) 

    if C<BM: 
     pes= BM-C 

    print ("le quedan ", pes, " ausencias o retardos 2") 

    if C==BM: 

     print ("No puede tener mas ausencias o retardos 2") 

    if C>BM: 

     print ("Ya se paso del maximo de ausencias o retardos 2") 



    improt.close() 

escoge = Button(ventana, text = "Escoge un archivo y despues escribe tu materia en el cuadro que corresponda", command = inicio).place(x =45, y = 30) 
cierra = Button(ventana, text = "Cierra", command = ventana.destroy).place(x = 50, y = 420) 

ventana.mainloop() 

答えて

0

お使いのシステムのデフォルトのファイルが使用している言語を想定すると、ASCII

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 25: ordinal not in range(128)

はあなたがFirefoxでファイルを開いた場合

#! /usr/bin/python  ## (your shebang may be slightly different) 
# -*- coding:latin-1 -*- 
## next line after the shebang 

## and then 
for line.decode('latin-1') in improt: 

を追加してみてください、ラテン-1でいるように見えます[表示]> [テキストエンコーディング]の順に選択すると、エンコーディングの内容がわかります。これを行うウェブサイトもあります。また、これは一般的な問題です(まれな例外ではありません)。 "UnicodeDecodeError: 'ascii'コーデックでバイトをデコードできない場合は、多くのヒットが発生します。

関連する問題