Еще один ночной проект. Я пытался сделать простой экран входа в систему (учетные данные будут использованы позже). Теперь я хочу сохранить имя пользователя и пароль в качестве переменных USERNAME и PASSWORD на «экране входа в систему». Почему-то не работает. Я пробовал так много вещей, как «global», «return» и т.д. c.
Есть ли способ сохранить входные данные в этих переменных без резкого изменения кода? Позже я немного изменю код, и мне нужно будет понять и объяснить это слишком многочисленным людям.
РЕДАКТИРОВАТЬ: в раскрывающемся меню есть опция под названием «-------». Я его туда никогда не клал, но он продолжает выскакивать. Есть ли причина, по которой он всегда всплывает? А как его удалить?
import os
import smtplib
from tkinter import *
import tkinter.messagebox
#USERNAME
#PASSWORD
root = Tk()
root.geometry("500x300")
root.title("E-mail-Sending program EBF")
# *** FUNCTIONS ***
def setLoginCredentials():
USERNAME = entryLoginUsername.get()
PASSWORD = entryLoginPassword.get()
print(USERNAME)
print(PASSWORD)
def loginCredentials(event):
#Create another screen
loginScreen = Toplevel(root)
loginScreen.title("login-screen")
loginScreen.geometry("300x300")
#LABELS LOGIN SCREEN
labelLoginUsername = Label(loginScreen, text="E-mail:")
labelLoginUsername.grid(row=0,column=0, sticky=E)
labelLoginPassword = Label(loginScreen, text="Password:")
labelLoginPassword.grid(row=1,column=0, sticky=E)
#ENTRIES LOGIN SCREEN
entryLoginUsername = Entry(loginScreen)
entryLoginUsername.grid(row=0,column=1)
entryLoginPassword = Entry(loginScreen)
entryLoginPassword.grid(row=1,column=1)
#LOGIN BUTTON
loginButton1 = Button(loginScreen,text="Login",command=setLoginCredentials)
# loginButton1.bind("<Button-1>", setLoginCredentials)
loginButton1.grid(row=2,column=1, sticky=W)
def previewEmail():
tkinter.messagebox.showinfo('Email preview','Dear professor <NAME>\n\n\nThis email is on behalf of the Academy Committee of EBF Groningen, which is responsible for the booksale of the Economics and Business Faculty of the University of Groningen.\n\nSince you are the coordinator of the course <NAME>, we were wondering if any alterations were made regarding the compulsory literature that has not been listed on the latest version of Ocasys yet.\n\nWe would like the confirmation if the course literature on Ocasys is up to date or if any alterations are needed. This way we are able to contact the suppliers of these books and ensure that inconveniences, due to providing the wrong books, can be avoided.\n\n\nMet vriendelijke groet,\nKind Regard,\n\n<SENDER> - <FUNCTION>\nAcademy Committee\nEBF Groningen\n')
# *** LABELS HOMESCREEN ***
labelSender = Label(root, text="Sender:")
labelSender.grid(row=0,column=0, sticky=E)
labelFunction = Label(root, text="Function:")
labelFunction.grid(row=1,column=0, sticky=E)
labelEmail = Label(root, text="Email:")
labelEmail.grid(row=2,column=0, sticky=E)
labelProfessor = Label(root, text="Professor:")
labelProfessor.grid(row=3,column=0, sticky=E)
labelCourse = Label(root, text="Course:")
labelCourse.grid(row=4,column=0, sticky=E)
# *** ENTRIES MAINSCREEN***
entrySender = Entry(root)
entrySender.grid(row=0,column=2, columnspan=2)
entryFunction = Entry(root)
entryFunction.grid(row=1,column=2, columnspan=2)
entryEmail = Entry(root)
entryEmail.grid(row=2,column=2, columnspan=2)
entryProfessor = Entry(root)
entryProfessor.grid(row=3,column=2, columnspan=2)
entryCourse = Entry(root)
entryCourse.grid(row=4,column=2, columnspan=2)
# *** ENTRIES LOGINSCREEN ***
# *** BUTTONS ***
loginButton = Button(root, text="Login")
loginButton.bind("<Button-1>", loginCredentials)
loginButton.grid(row=6,column=0, sticky=E)
# *** MAIN MENU ***
menu= Menu(root)
root.config(menu=menu)
subMenu = Menu(root)
menu.add_cascade(label="Menu", menu=subMenu)
subMenu.add_command(label="Preview", command=previewEmail)
root.mainloop()