I have encountered a strange problem whilst creating my a-level computing project.
I have 3 modules: mainMenu.py , adminValidation.py and newUser.py
adminValidation is displayed below:
from tkinter import *
import tkinter.messagebox
print(password.get()) ##testing
def enter(event):
global password
if (password.get()).lower() == "pass":
adminValidation.destroy()
import newUser
else:
tkinter.messagebox.showinfo("Alert","Invalid password")
adminValidation = Tk()
password = StringVar()
##Labels
label_enter = Label(adminValidation, text ="Enter administrator password:").grid(row=0, column =0)
##text entry box
entry_password = Entry(adminValidation, textvariable = password)
entry_password.grid(row = 0, column = 1)
entry_password.config(show="*")
##button
button_enter = Button(adminValidation, text = "Enter")
button_enter.grid(row= 0, column = 2)
##bind to function
button_enter.bind("<Button-1>",enter)
adminValidation.bind("<Return>",enter)
adminValidation.mainloop()
When adminValidation is executed by itself, the StringVar() works correctly storing the correct user input. This allows the if statement to be triggered. This then imports newUser etc.
However, when mainMenu is executed (triggering the import of adminValidation) the text entered by the user is not stored in the StringVar(). When I print the StringVar() for testing, it appears blank.
If anyone has a solution, please let me know, thanks.
Tkinstances which leads to Variables not being properly updated