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.
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.
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)
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