2017-08-07 16 views
0

當iIrun這個程序有一個語法錯誤和「def überprüfen()」被標記爲紅色。哪裏不對?無效的語法錯誤,Tkinter的,功能

from tkinter import * 
password = str(eval(entry.get()) 

在這一部分是語法錯誤:

def überprüfen(event): 
    if password: 
       if len(password) > 8: 
         res.configure(text = "Ihr Passwort ist zu kurz") 
       else: 
         res.configure(text = "Ihr Passwort ist gut") 
    else: 
       res.configure(text = "Bitte geben sie ihr Passwort ein") 


w = Tk() 
Label(w, text="Ihr Passwort: ").pack() 
entry = Entry(w) 
entry.bind("<Return>", überprüfen()) 
entry.pack() 
res = Label(w) 
res.pack() 
w.mainloop() 

程序應該測試密碼,如果是好的。 感謝您的幫助:d

+1

加上'# - * - 編碼:UTF-8 - * - '你的源文件的第一行。或者使用ascii字符來定義標識符。 – stamaimer

+1

的'從... import'線不應該被縮進,也不應該在'def'線。另外,'password ='行缺少第三個''''。 –

+0

如果您真的在使用Python 3,請確保該文件保存爲UTF-8。沒有其他任何事情需要做,以允許unicode標識符。 – poke

回答

0

在你的代碼的第一行加入這一行。

# -*- coding: utf-8 -*-

+0

由於OP被使用Python 3,指定編碼明確那樣[沒有必要](https://stackoverflow.com/q/14083111/216074)和可能應該甚至被避免。 – poke