Reputation: 327
for my program i am using tkinter for the GUI. Before the program starts i want to have to input a password. I used the input() function. When running my code in my jupyter notebook everything works fine. So i created and executable file with pyinstaller, but when double clicking it won´t start and ask for the input. Since i often used pyinstaller i don´t think i failed in creating the exe-file, so my guess is, that the problem lies within the input() function. Is there another way to ask for user input?
I tried creating a window with an entry widget via Toplevel but i am not quite sure how to implement it since i want to start the program AFTER i entered the password.
My relevant code:
if __name__=='__main__':
root = tkinter.Tk()
asd = input("Enter the password:")
if asd == str(12345):
app = GUI(master=root)
app.master.title("Programm Links")
app.master.minsize(600,400)
root.config(menu=app.menubar)
app.center(root)
app.mainloop()
else:
root.destroy()
Upvotes: 1
Views: 574
Reputation: 327
So with help of the comments on my question i got an answer:
import tkinter
from tkinter import messagebox
from tkinter import simpledialog
if __name__=='__main__':
root = tkinter.Tk()
root.withdraw()
asd = tkinter.simpledialog.askstring("Password","Enter the password:")
if asd == str(12345):
app = GUI(master=root)
app.master.title("Programm Links")
app.master.minsize(600,400)
root.config(menu=app.menubar)
app.center(root)
app.mainloop()
else:
messagebox.showwarning("WRONG PASSWORD","You entered a wrong password")
root.destroy()
This creates a dialogbox that asks for a user input. root.withdraw() hides the root window frame that gets created by root = tkinter.Tk() which is needed for the dialogbox to run.
Upvotes: 2