This is a piece of code I write for this question: Entry text on a different window?
It is really strange what happened at mySubmitButton, it appears that the button does not want to appear when it is first started, it will, however appear when you click on it. Even if you click on it and release it away from the button, that way it won't be send. I am suspecting if this only happen on a mac, or it only happen to my computer, because it is a very minor problem. Or it is something silly I did with my code.
self.mySubmitButton = tk.Button(top, text='Hello', command=self.send)
self.mySubmitButton.pack()
Am I missing something? I googled and found this question and answer on daniweb. And I do a diff on them, can't figure out what he did "fixed", but I did see the line is changed to command=root.quit. But it is different from mine anyway...
Here is the full source code, and there is no error message, but the button is just missing.
import tkinter as tk
class MyDialog:
def __init__(self, parent):
top = self.top = tk.Toplevel(parent)
self.myLabel = tk.Label(top, text='Enter your username below')
self.myLabel.pack()
self.myEntryBox = tk.Entry(top)
self.myEntryBox.pack()
self.mySubmitButton = tk.Button(top, text='Hello', command=self.send)
self.mySubmitButton.pack()
def send(self):
global username
username = self.myEntryBox.get()
self.top.destroy()
def onClick():
inputDialog = MyDialog(root)
root.wait_window(inputDialog.top)
print('Username: ', username)
username = 'Empty'
root = tk.Tk()
mainLabel = tk.Label(root, text='Example for pop up input box')
mainLabel.pack()
mainButton = tk.Button(root, text='Click me', command=onClick)
mainButton.pack()
root.mainloop()
Adding another button right after this one, the second one actually appear. I thought it might be because I didn't call the same function, but I called the same one and it does the exact same thing it appears...
Adding a empty label between them, doesn't work. The button still isn't being draw.
PS: I am using Mac OS 10.5.8, and Tk 8.4.7.
I see the hello button, but I'm on windows 7.
I did a quick re-write of your example. I'll be curious if it makes any difference for you.
import tkinter as tk
class GUI(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
mainLabel = tk.Label(self, text='Example for pop up input box')
mainLabel.pack()
mainButton = tk.Button(self, text='Click me', command=self.on_click)
mainButton.pack()
top = self.top = tk.Toplevel(self)
myLabel = tk.Label(top, text='Enter your username below')
myLabel.pack()
self.myEntryBox = tk.Entry(top)
self.myEntryBox.pack()
mySubmitButton = tk.Button(top, text='Hello', command=self.send)
mySubmitButton.pack()
top.withdraw()
def send(self):
self.username = self.myEntryBox.get()
self.myEntryBox.delete(0, 'end')
self.top.withdraw()
print(self.username)
def on_click(self):
self.top.deiconify()
gui = GUI()
gui.mainloop()
Related
My aim is to generate a window with a button "NewWindow" on it. If I press the button, the program should open a new window. This window I stored in a class "NewWindow" to quickly reproduce it.
In this "NewWindow" I have another button. If I press it the label of basic window should be updated and the window "NewWindow" should be closed automatically.
Here is my code:
from tkinter import *
class NewWindow(Toplevel):
def __init__(self, master = None):
super().__init__(master = master)
self.title('NewWindow')
self.lb = Label(self, text='Hello')
self.lb.grid(column=0, row=0, columnspan=1)
self.bt1 = Button(self, text="apply Hello", command= self.bt_press)
self.bt1.grid(column=0, row=1)
def bt_press(self):
window.basic_lb.text = "Hello"
window = Tk()
def new_Editor():
a = NewWindow(window)
window.title("BasicWindow")
window.basic_lb = Label(window, text='None')
window.basic_lb.grid(column=0, row=0, columnspan=1)
window.basic_bt = Button(window, text="NewWindow", command=new_Editor)
window.basic_bt.grid(column=0, row=1)
window.mainloop()
Problems:
At start both windows NewWindow and BasicWindow are displayd. I only want to open BasicWindow and NewWindow should be opened after button basic_bt is clicked. How can I solve it? (already solved by commed below)
Why the label text in basic_lb did not get some update after pressing self.bt1?
How is it possible to close NewWindow with use of bt_press method?
You have a few typos/errors in your code that are casuing some of your problems. As #Tim said, when you pass a function to a command like command=function(), it will be called on runtime, not when the button is pressed. You need to pass the function handle to the command, command=function. You got around this by using a lambda function in your button command, but it is easier to just have command=self.bt_press
Answering your second question, window.basic_lb.text = "Hello" is not how you change the text in a tkinter Label, use <Label>.config(text="Hello"). You also should use self.master and define self.master = master in __init__ instead of just using window, because while you can access window due to it not being defined in local scope, it's better to explicitly define it.
You can close a window using window.destroy().
Your working code is now:
from tkinter import *
class NewWindow(Toplevel):
def __init__(self, master = None):
super().__init__(master = master)
self.title('NewWindow')
self.master = master
self.lb = Label(self, text='Hello')
self.lb.grid(column=0, row=0, columnspan=1)
self.bt1 = Button(self, text="apply Hello", command=self.bt_press)
self.bt1.grid(column=0, row=1)
def bt_press(self):
self.master.basic_lb.config(text="Hello")
self.destroy()
window = Tk()
def new_Editor():
a = NewWindow(window)
window.title("BasicWindow")
window.basic_lb = Label(window, text='None')
window.basic_lb.grid(column=0, row=0, columnspan=1)
window.basic_bt = Button(window, text="NewWindow", command=new_Editor)
window.basic_bt.grid(column=0, row=1)
window.mainloop()
I am trying to use a tkinter Toplevel window with a Text box to post to a Text box in the main window, but I keep getting the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\someone\ouch\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "<ipython-input-14-df46ff30dac4>", line 21, in GetFromDIALOG
X = littletext.get("1.0","end")
NameError: name 'littletext' is not defined
In my script below, I call the Text widget in the Toplevel "littletext" and the Text widget in the main window "BIGTEXT". I also tried setting the Text boxes as StringVars, as most tutorials and scripts seem to suggest is right, but StringVars seem to work more on Entry (not Text) boxes.
I am wondering if I should use a custom class instead of a Toplevel, although I am not sure how I would handle that would work either.
My code is below.
import tkinter as tk
def openDIALOG(window):
DIALOG = tk.Toplevel(window)
DIALOG.title("DIALOG")
DIALOG.geometry("400x300+100+100")
littletext = tk.Text(DIALOG, height=15)
littletext.pack()
btn1 = tk.Button(DIALOG, text ="POST TO MAIN WINDOW", command=GetFromDIALOG)
btn1.pack(side="left")
btn2 = tk.Button(DIALOG, text ="EXIT", command = DIALOG.destroy)
btn2.pack(side="left")
def GetFromDIALOG ():
X = littletext.get("1.0","end")
print(X)
window = tk.Tk()
window.title("main")
menubar = tk.Menu(window)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="RUN A DIALOG", command=lambda:openDIALOG(window))
filemenu.add_command(label="Exit", command=window.destroy)
menubar.add_cascade(label="FILE", menu=filemenu)
window.config(menu=menubar)
BIGTEXT = tk.Text(window)
BIGTEXT.pack()
BUTTON = tk.Button(window, text="Post", command=openDIALOG)
BUTTON.pack()
window.mainloop()
One way to fix the NameError, which is due it it being a local variable in the openDIALOG() function in your code, is to make it an attribute of instances of the class. This is better than using a global variable, which is another option, but global variables are bad.
Stackoverflow is not intended to replace existing tutorials or documentation, so I'll describe only very briefly what the demo code below it doing. This topic would be covered much more thoroughly in most of the Python tutorials that are available online, if you took time to for them.
So, here's how that might be done based on the code in your question. Notice how littletext is now self.littletext. This is because it has been turned into a class attribute of the class MY_DIALOG that's been defined, so it can be access through the self argument which will automatically be passed as the first argument of all the class' functions (which are know as class "methods").
import tkinter as tk
from tkinter.constants import *
class MyDialog:
def __init__(self, window):
DIALOG = tk.Toplevel(window)
DIALOG.title("DIALOG")
DIALOG.geometry("400x300+100+100")
self.littletext = tk.Text(DIALOG, height=15)
self.littletext.pack()
btn1 = tk.Button(DIALOG, text="POST TO MAIN WINDOW", command=self.GetFromDIALOG)
btn1.pack(side="left")
btn2 = tk.Button(DIALOG, text="EXIT", command=DIALOG.destroy)
btn2.pack(side="left")
def GetFromDIALOG(self):
X = self.littletext.get("1.0", END)
print(X)
if __name__ == '__main__':
window = tk.Tk()
window.title("main")
menubar = tk.Menu(window)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="RUN A DIALOG", command=lambda: MyDialog(window))
filemenu.add_command(label="Exit", command=window.destroy)
menubar.add_cascade(label="FILE", menu=filemenu)
window.config(menu=menubar)
BIGTEXT = tk.Text(window)
BIGTEXT.pack()
BUTTON = tk.Button(window, text="Post", command=lambda: MyDialog(window))
BUTTON.pack()
window.mainloop()
Thanks martineau! :)
There was a few small problems I cleaned up.
The dialog you coded didnt post back to BIGTEXT in the main window, so I completed the callback aspect of it.
The BUTTON in the footer of the main window was actually a mistake on my part. I accidentally forgot to delete it in the original post, so I deleted it here and let the menu work the call.
Final code is below.
import tkinter as tk
from tkinter.constants import *
class MY_DIALOG:
def __init__(self, window):
DIALOG = tk.Toplevel(window)
DIALOG.title("DIALOG")
DIALOG.geometry("400x300+100+100")
self.littletext = tk.Text(DIALOG, height=15)
self.littletext.pack()
btn1 = tk.Button(DIALOG, text="POST TO MAIN WINDOW", command=self.GetFromDIALOG)
btn1.pack(side="left")
btn2 = tk.Button(DIALOG, text="EXIT", command=DIALOG.destroy)
btn2.pack(side="left")
def GetFromDIALOG(self):
X = self.littletext.get("1.0","end")
BIGTEXT.insert("end", X)
self.littletext.delete("1.0","end")
if __name__ == '__main__':
window = tk.Tk()
window.title("main")
menubar = tk.Menu(window)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="RUN A DIALOG", command=lambda: MY_DIALOG(window))
filemenu.add_command(label="Exit", command=window.destroy)
menubar.add_cascade(label="FILE", menu=filemenu)
window.config(menu=menubar)
BIGTEXT = tk.Text(window)
BIGTEXT.pack()
window.mainloop()
I've got some code that opens a textbox so the user can input an EAN and then it scrapes the web. It all works fine except for some reason a mysterious second textbox opens with the original one and unless you use that one to close the program, it stops responding.
class MyDialog:
def __init__(self, parent): #Pop-up textbox
top = self.top = Toplevel(parent)
Label(top, text="Product EAN").pack() #pop-up box text
self.e = Entry(top, cursor = "xterm", width=25) #Input textbox
self.e.pack(padx=40)
b = Button(top, text="Submit", command=self.ok, cursor = "hand2") #Submit button for pop-up box
b.pack(pady=5)
....
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
That's all the code to do with textboxes - self.ok is the scraper so is unimportant to this issue. Could someone explain to me or help me fix the issue as I can't see why the following picture is the output from that.
Thank you in advance.
The problem is you are opening a Tk() window and then another, TopLevel() window on top of that, if all you want is one window, the you just use the Tk() window. (The problem is a little unclear, but this is what I assume you are asking).
To fix this you can just remove the TopLevel() window. Like so:
class MyDialog:
def __init__(self, parent): #Pop-up textbox
Label(parent, text="Product EAN").pack() #pop-up box text
self.e = Entry(parent, cursor = "xterm", width=25) #Input textbox
self.e.pack(padx=40)
b = Button(parent, text="Submit", command=self.ok, cursor = "hand2") #Submit button for pop-up box
b.pack(pady=5)
root = Tk()
d = MyDialog(root)
root.mainloop()
The Incorrect-Dimiss button erases on click and when Return key is pressed, but if I enter anything afterwards, nothing happens. The issue is that if I enter it correct, the login button pops up and it works. If I enter it incorrect, the dismiss button pops up, and clicking or pressing enter erases it. Now, anything I enter after an incorrect attempt whether correct or incorrect does nothing.
(1) In order to avoid this, I was wondering if the program could just restart on clicking/pressing enter the dismiss button, without the window closing, or another reopening, but I do not know how to do this.
(2)Also is there a max login attempts code that ends/restarts the program and if so how would I place it in this code? (something like if >3 incorrect then quit)
Here is the code (python3)- try it for yourself if you would like:
from tkinter import *
class Application(object):
def __init__(self, event=None):
self.root = Tk()
self.root.configure(bg="darkorchid1", padx=10, pady=10)
self.root.title("WELCOME")
self.username = "Bob"
self.welcome = Label(self.root, text="WELCOME TO MY PROGRAM", bg="lightgrey", fg="darkorchid1")
self.welcome.pack()
self.label0 = Label(self.root, text="ENTER NAME:", bg="purple", fg="white", height=5, width=50)
self.label0.pack()
self.entry = Entry(self.root, width=25)
self.entry.configure(fg= "white",bg="grey20")
self.entry.pack()
self.entry.bind("<Return>", self.submit)
self.button = Button(self.root, text="SUBMIT", highlightbackground="green", width=48, command=self.submit)
self.button.pack()
def submit(self, event=None):
username = self.entry.get()
if username == self.username:
self.button1 = Button(self.root, text='LOGIN', highlightbackground="green", width=28, command=self.root.destroy)
self.button1.pack()
self.entry.bind("<Return>", self.login)
else:
self.button2 = Button(self.root, text="INCORRECT- CLICK TO DIMISS THIS MESSAGE", highlightbackground="red", width=48, command=self.incorrect)
self.button2.pack()
self.entry.bind("<Return>", self.incorrect)
def incorrect(self, event=None):
self.button2.destroy()
def login(self, event=None):
self.root.destroy()
app=Application()
mainloop()
Instead of destroying the button I want this to restart the program but cannot find the correct command. This would destroy the button since it doesn't exist at the beginning of the program, as well as allow for incorrect or correct input to actually work after the first try.
def incorrect(self, event=None):
self.button2.destroy()
I am a beginner so the more simple, the better at this point. Thank you.
Not an expert myself but fiddled with TKinter some time ago. From what I know the only way to restart a TKinter app is by running it in a thread and then killing and restarting that thread. I would recommend you to take a look at Python's multiprocessing or threading module.
Something you could also try (which worked for me in that past, but isn't really the correct way of doing this I suppose) is to have ROOT = Tk()as a global variable, then having your submit-button as a stand-alone class and have it import global ROOT before executing ROOT.Destroy() and then have it call the application class again, which can also call the global variable (which would cause it to start again). It's a method I've used to have the TKinter window update while I was using it. But the threading method is often mentioned as the proper way of doing this as far as I know..
As a very limited example (short on time for a more extensive one), I did something like this in my old script:
ROOT_WINDOW = ""
VARIABLE1 = 'some variable here'
def func1():
global ROOT_WINDOW
global VARIABLE1
ROOT_WINDOW = Tk()
#(Insert application code that uses or requires variable1)
func2()
def func2():
global ROOT_WINDOW
global VARIABLE1
ROOT_WINDOW.Destroy()
Change variable1
func1()
With regard to setting a maximum number of login attempts. I solved this by creating a separate startup script. It works correctly but I dare not to post it here as it is a real ugly and incorrect way of solving the problem that also comes with a security issue (of having to store your sudo password within a variable).
Sorry for not being able to be of more help.
First of all I would change the bind to return to the root window instead of the entry (otherwise you have to click on the entry field for the return to have an effect)
Next you need 3 state variables for your class.
self.button1 = None
self.button2 = None
self.attempts = 0
Then by checking the state of each you can accomplish (what I think) you want
Here’s the whole code modified
from tkinter import *
class Application(object):
def __init__(self, event=None):
self.root = Tk()
self.root.configure(bg="darkorchid1", padx=10, pady=10)
self.root.title("WELCOME")
self.username = "Bob"
self.welcome = Label(self.root, text="WELCOME TO MY PROGRAM", bg="lightgrey", fg="darkorchid1")
self.welcome.pack()
self.label0 = Label(self.root, text="ENTER NAME:", bg="purple", fg="white", height=5, width=50)
self.label0.pack()
self.entry = Entry(self.root, width=25)
self.entry.configure(fg= "white",bg="grey20")
self.entry.pack()
self.root.bind("<Return>", self.submit)
self.button = Button(self.root, text="SUBMIT", highlightbackground="green", width=48, command=self.submit)
self.button.pack()
self.button1 = None
self.button2 = None
self.attempts = 0
def submit(self, event=None):
username = self.entry.get()
if username == self.username:
if (self.button2 != None): # after I added disabling the submit button this check might not be necessary
return
if (self.button1 == None):
self.button1 = Button(self.root, text='LOGIN', highlightbackground="green", width=28, command=self.root.destroy)
self.button1.pack()
self.root.bind("<Return>", self.login)
self.button.config(state="disabled")
else:
if (self.button2 == None):
self.button2 = Button(self.root, text="INCORRECT- CLICK TO DIMISS THIS MESSAGE", highlightbackground="red", width=48, command=self.incorrect)
self.button2.pack()
self.root.bind("<Return>", self.incorrect)
self.button.config(state="disabled")
def incorrect(self, event=None):
self.attempts += 1
if (self.attempts > 2):
self.root.destroy()
else:
self.root.bind("<Return>", self.submit)
self.button.config(state="normal")
self.button2.destroy()
self.button2 = None
def login(self, event=None):
self.root.destroy()
app=Application()
mainloop()
I want to have a login window pop up at first, then once the conditions are satisfied, it closes the login window and opens a new window.
from Tkinter import *
import tkMessageBox
#Not really sure what i'm doing here anymore
while True:
Login = Tk()
Login.title('Login')
Login.geometry('400x130')
NameLabel = Label(Login, text='Username')
NameLabel.place(bordermode=OUTSIDE, height=25, width=100, x=100)
NameEntryRaw = Entry(Login)
NameEntryRaw.place(bordermode=OUTSIDE, height=25, width=100, x=200)
CodeLabel = Label(Login, text='Code')
CodeLabel.place(bordermode=OUTSIDE, height=25, width=100, x=100, y=30)
CodeEntryRaw = Entry(Login)
CodeEntryRaw.place(bordermode=OUTSIDE, height=25, width=100, x=200, y=30)
def tbd():
tkMessageBox.showinfo('Congrats!', 'This program is not done yet')
def login():
Usernames=list()
Usernames.append('Mordecai')
Usernames.append('Ezekiel')
Usernames.append('Goliath')
Usernames.append('Abraham')
Usernames.append('Bartholomew')
Usernames.append('Jedediah')
Usernames.append('Solomon')
Usernames.append('Tobias')
Usernames.append('Yohanan')
Usernames.append('Lucifer')
NameEntry=NameEntryRaw.get()
CodeEntry=CodeEntryRaw.get()
CodeReal='116987'
if Usernames.count(NameEntry) == 0:
tkMessageBox.showinfo('Error!', 'Your Username is invalid! Try Again.')
else:
()
if CodeEntry != CodeReal:
tkMessageBox.showinfo('Error!', 'The Code entered is invalid! Try Again.')
else:
()
LoginButton = Button(Login, text="Login", command=login)
LoginButton.place(bordermode=OUTSIDE, height=50, width=200, x=100, y=60)
Login.mainloop()
else:
DataBase = Tk()
#this will be the data base
DataBase.mainloop()
You don't want to use two mainloop's. Generally speaking, your tkinter app should have a single .mainloop called.
As for how to get the login popup and then switch to the window... You can create your root window with the app and when you start your program have a Toplevel window be shown with the login stuff, maybe hide / withdraw the root additionally?, have the toplevel have a submit button or something that would validate the credentials. If the credentials are valid, then you can use the destroy() method and remove the toplevel widget / go to the root window for your main app.
Having a while True repeat the process of creating a GUI + mainloop is bad for obvious reasons.
Edit: static is probably a bad term for a mutable object, since it's mutable... Added tuple vs list for global.
You don't need to create a blank list and then use append to add your usernames to the usernames list. You can make this global. Since, username is a mutable object (it's a list) you could still perform operations elsewhere in your code on this global, say .append etc. Or, if you never have these change i'd make it a tuple, since they're immutable and this "fits" better with the intent.
Instead of using .count(*) to get the occurrences of an element in a list you can just use:
if (object) in (some list) #Object is an abstraction, not the type
If CodeReal is static, which it looks to be, you can also make this global.
Here's a quick edit to your code, you can do this without classes, but I used classes here to try to distinctly show the logical separation in the program.
I changed a few variable names as well, so that it was easier to read / understand. I also used .pack() and .grid() as this was quicker to code than having to use .place() everywhere this is an arbitrary choice.
import Tkinter as tk
import tkMessageBox as messagebox
import sys
#No need to do usernames = list() and then .append for each one.
#Just make a global list holding them all...
USERNAMES = ('Mordecai', 'Ezekiel', 'Goliath', 'Abraham', 'Bartholomew',
'Jedediah', 'Solomon', 'Tobias', 'Yohanan', 'Lucifer')
PASSWORD = '116987' #Was CodeReal, this can be global
#We overrode the closing protocol here.
def closing_protocol():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
sys.exit()
#A container for our Login "app".
class Login(tk.Toplevel):
def __init__(self, *args, **kwargs):
#We init the toplevel widget.
tk.Toplevel.__init__(self, *args, **kwargs)
#We set the closing protocol to be the overridden version / func.
self.wm_protocol("WM_DELETE_WINDOW", closing_protocol)
tk.Label(self, text='Username').grid(row=0, column=0)
self.username = tk.Entry(self)
self.username.grid(row=0, column=1)
tk.Label(self, text='Password').grid(row=1, column=0)
#Show = '*' just hides the password instead of plain-text like
#you typically see
self.password = tk.Entry(self, text='Password', show='*')
self.password.grid(row=1, column=1)
#When the button is clicked the _callback function will be called
tk.Button(self, text='Login', command=self._callback).\
grid(row=2, column=0, columnspan=2, sticky="nsew")
def _callback(self):
#If the username or password is bad, raise an error message.
if (self.username.get() not in USERNAMES or
self.password.get() != PASSWORD):
messagebox.showerror("Validation Error!",
"You have entered invalid credentials.\n" +
"Please try again.")
#otherwise, we're good to go. Destroy login / show main app.
else:
root.deiconify()
app.pack()
self.destroy()
class Main(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
tk.Label(self, text="MAIN APP STUFF").pack()
if __name__ == '__main__':
root = tk.Tk()
root.withdraw() #Hides the root window initially.
app = Main(root)
Login()
root.mainloop()
I want to thank you for clarifying what you did for me. It proved to be very helpful! Here is what I've settled with. I put the names back and made it to work without classes, as I found it a little too difficult to work with.
from Tkinter import *
import tkMessageBox
import sys
import binascii #Not for this part
Codenames = ['Mordecai', 'Ezekiel', 'Goliath', 'Abraham', 'Bartholomew',
'Jedediah', 'Solomon', 'Tobias', 'Yohanan', 'Lucifer']
Password = '116987'
def close_protocol():
if tkMessageBox.askokcancel("Quit", "Do you want to quit?"):
sys.exit()
#Below for a later part...
def text_to_bits(text, encoding='utf-8', errors='surrogatepass'):
bits = bin(int(binascii.hexlify(text.encode(encoding, errors)), 16))[2:]
return bits.zfill(8 * ((len(bits) + 7) // 8))
def text_from_bits(bits, encoding='utf-8', errors='surrogatepass'):
n = int(bits, 2)
return int2bytes(n).decode(encoding, errors)
def int2bytes(i):
hex_string = '%x' % i
n = len(hex_string)
return binascii.unhexlify(hex_string.zfill(n + (n & 1)))
#Above for a later part...
SDB = Tk()
SDB.title("SMEGJALBYT DATA BASE")
SDB.withdraw()
SDBLogin = Toplevel()
SDBLogin.title("Login")
SDBLogin.wm_protocol("WM_DELETE_WINDOW", close_protocol)
CodenameLabel = Label(SDBLogin, text="Codename")
CodenameLabel.grid(row=0, column=0)
CodenameEntry = Entry(SDBLogin)
CodenameEntry.grid(row=0, column=2)
PasswordLabel = Label(SDBLogin, text="Password")
PasswordLabel.grid(row=1, column=0)
PasswordEntry = Entry(SDBLogin, show='*')
PasswordEntry.grid(row=1, column=2)
def login_operation():
if CodenameEntry.get() not in Codenames:
tkMessageBox.showinfo("INVALID CODENAME!", "Please verify input in the 'Codename' field")
elif PasswordEntry.get() != Password:
tkMessageBox.showinfo("INVALID PASSWORD!", "Please verify input in the 'Password' field")
else:
SDB.deiconify()
SDBLogin.destroy()
LoginButton = Button(SDBLogin, text="Login", command=login_operation)
LoginButton.grid(row=2, column=1)
#Code continues...
#Code finisles....
SDB.mainloop()
This has the same basic functionality, just organised the way I wanted it.