2017-10-11 5 views
-1

ユーザー名やパスワードが間違っている場合は、tkinter-pythonでポップアップする代わりに、フィールドの境界を赤で変更しますか?ユーザー名またはパスワードが間違っている場合、入力フィールドの境界を赤くするにはどうすればいいですか?

ユーザーネームコード

self.username_entry = Entry(
     self.frame, bg="white", bd=2, 
     font=self.USERNAME_ENTRY_FONT, relief=FLAT, highlightthickness=1, highlightbackground="black", 
     selectbackground="yellow", highlightcolor='#4584F1') 
    self.username_entry.place(
     relx=float(self.USERNAME_ENTRY_X)/self.VIRTUAL_WIDTH, 
     rely=float(self.USERNAME_ENTRY_Y)/self.VIRTUAL_HEIGHT, 
     relheight=float(60)/768, relwidth=float(454)/1366) 
    self.username_entry.bind('<FocusIn>', self.username_entry_handler) 
    self.username_entry.bind('<FocusOut>', self.username_entry_handler) 

Pwdのコード

self.password_entry = Entry(
     self.frame, bg="white", bd=2, 
     font=self.PASSWORD_ENTRY_FONT, relief=FLAT, highlightthickness=1, highlightbackground="black", 
     selectbackground="yellow", show='*', highlightcolor='#4584F1') 
    self.password_entry.place(
     relx=float(self.PASSWORD_ENTRY_X)/self.VIRTUAL_WIDTH, 
     rely=float(self.PASSWORD_ENTRY_Y)/self.VIRTUAL_HEIGHT, 
     relheight=float(60)/768, relwidth=float(454)/1366) 
    self.password_entry.bind('<FocusIn>', self.password_entry_handler) 
    self.password_entry.bind('<FocusOut>', self.password_entry_handler) 
    self.password_entry.bind("<Tab>", no_op) 
+0

実際に私は[MCVE](https://stackoverflow.com/help/mcve)をインポートする必要があります。ここで本当に重要なのは、使用しているEntry(tkinterまたはttk)の種類です。 –

+0

私はtkinter @ j_4321を使っています – venkat

答えて

0

ログインに失敗した場合は、両方の入力フィールドのために赤のオプションhighlightcolorhighlightbackgroundを設定することができます。何かが好きです:

import tkinter as tk 
root = tk.Tk() 

def login(): 
    # login/passord checking 
    right_login = False 

    if right_login: 
     print('logged in') 
    else: 
     username_entry.configure(highlightbackground='red', highlightcolor='red') 
     password_entry.configure(highlightbackground='red', highlightcolor='red') 

username_entry = tk.Entry(root, bg="white", bd=2, relief='flat', 
          highlightthickness=1, 
          highlightbackground="black", 
          selectbackground="yellow", 
          highlightcolor='#4584F1') 
password_entry = tk.Entry(root, bg="white", bd=2, relief='flat', 
          highlightthickness=1, highlightbackground="black", 
          selectbackground="yellow", show='*', 
          highlightcolor='#4584F1') 

username_entry.pack() 
password_entry.pack() 

tk.Button(root, text='Log In', command=login).pack() 
root.mainloop() 
関連する問題