Easy password box in Python

background

Since it was necessary to enter the user's password when executing a Python command, I created a pop-up to enter the password with a simple code.

reference

Tkinter has little information and is a little inconvenient to use, but posted by nnahito is well organized, so I think it will be helpful.

code

The operation was done with python 2.7.10. Tkinter is built into the python standard, so you don't need to install it. Since the code is minimal, if you want to change the GUI, please change the code below.

# -*- coding: utf-8 -*-
import Tkinter

class PswdBox(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self)
        self.title('Enter password')
        self.ent = Tkinter.Entry(self, show='*')
        self.ent.pack()
        self.lbl = Tkinter.Label(self, foreground='#ff0000')
        self.lbl.pack()
        self.btn = Tkinter.Button(self, text='Submit', command=self.submit)
        self.btn.pack()
        #Define the correct password here or import from a file, etc.
        self.correct_pass = 'pass'

    def submit(self):
        self.pswd = self.ent.get()
        if self.pswd == self.correct_pass: #correct
            self.destroy() #close the window
        else: #Wrong
            self.lbl['text'] = 'Try again!'
            print(self.pswd)


if __name__ == '__main__':
    pb = PswdBox()
    pb.mainloop()
    print(pb.pswd)

Execution result

How to use Save the above code to pswdbox.py and your desktop as appropriate and in the terminal

python ~/Desktop/pswdbox.py

If you enter, it will start. パスワードボックス実行結果

Recommended Posts

Easy password box in Python
Gacha written in Python -BOX gacha-
Password generation in texto with python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Python is easy
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
nCr in python
N-Gram in Python
Programming in python
Easy way to use Wikipedia in Python
Plink in Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
Easy image processing in Python with Pillow
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
I created a password tool in Python.
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Super easy! Python + Flask environment in Docker quickly
Experiment with NIST 800-63B password rules in Python
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Singleton pattern in Python
File operations in Python
Key input in Python
Daily AtCoder # 33 in Python
Logistic distribution in Python
Daily AtCoder # 7 in Python
LU decomposition in Python
One liner in Python
Daily AtCoder # 24 in Python