Re: [Tutor] login window using Tk
On 02/11/11 05:05, Chris Hare wrote: def verifyLogin(self): farmid = list.get(ACTIVE) userid = login_userid.get() login_passwd = login_passwd.get() gets called, but I get the error Exception in Tkinter callback farmid = list.get(ACTIVE) AttributeError: type object 'list' has no attribute 'get' When the frame controls were added, list is defined as list = Listbox(frame) names defined in functions are local to that function. They can't be seen outside of the function. So... To be able to access the controls you need to add themas instance attributes to your class. so you should use self.list = Listbox( and farmid = self.list.get( What you are seeing is Python looking for something called list in your methods namespace and not finding it. It can't see anything global either so it picks up the built-in list() type. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
Just thought I would drop y'all a note and say thank you for your help on this. I have the login code working. I learned a bunch from you guys. Thanks! Chris Hare ch...@labr.net http://www.labr.net On Nov 2, 2011, at 5:02 AM, Alan Gauld wrote: On 02/11/11 05:05, Chris Hare wrote: def verifyLogin(self): farmid = list.get(ACTIVE) userid = login_userid.get() login_passwd = login_passwd.get() gets called, but I get the error Exception in Tkinter callback farmid = list.get(ACTIVE) AttributeError: type object 'list' has no attribute 'get' When the frame controls were added, list is defined as list = Listbox(frame) names defined in functions are local to that function. They can't be seen outside of the function. So... To be able to access the controls you need to add themas instance attributes to your class. so you should use self.list = Listbox( and farmid = self.list.get( What you are seeing is Python looking for something called list in your methods namespace and not finding it. It can't see anything global either so it picks up the built-in list() type. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Wed, 2 Nov 2011 11:54:17 am Alan Gauld wrote: On 01/11/11 21:15, Joel Montes de Oca wrote: Question, once the code is compiled to a binary, can someone inject code to cause the hidden window to show, skipping the login altogether? In general you don't compile Python to a binary, although tools exist that give a good approximation to that. But to inject code would need access to the source files A sufficiently clever byte-code hacker can insert byte-code straight into the .pyc file, given write permission to the files -- or an exploit that allows writing to a file. Since people can modify machine code executables (that's how most viruses work, and cracked applications), modifying byte-code is unlikely to give them any trouble. Here's a proof-of-concept virus that does exactly that: http://www.symantec.com/connect/blogs/python-has-venom -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01-Nov-11 09:47, Chris Hare wrote: Questions: 1. Is this the best way of doing this or is there a better way? 2. How do I exit the main loop when the user has authenticated? Why stop the main loop and restart it? Typically you'd setup the app, and start the main loop running for the duration. Everything else is handled by the application's logic. For example, you'd display the login toplevel window, and when it's satisfied, it can trigger the functionality which creates (or displays the pre-created but hidden) application window and dismisses the login toplevel. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
I am also intrested in this topic. Chris were you thinking of using the window.hide() method? -Joel M On Nov 1, 2011 1:21 PM, Chris Hare ch...@labr.net wrote: I am working on a python Tk program which involves a login window and I am looking for some advice. Currently the code I have creates a window (Toplevel) where the login controls are and I am running that using a main loop for the window. The root window is hidden. The objective is that when the user ha successfully authenticated, the login window is closed or the main loop os exited and then the root window is shown and the main loop started for the actual application. Questions: 1. Is this the best way of doing this or is there a better way? 2. How do I exit the main loop when the user has authenticated? Thanks Chris Hare ch...@labr.net http://www.labr.net Chris Hare ch...@labr.net http://www.labr.net ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01/11/11 16:47, Chris Hare wrote: I am working on a python Tk program which involves a login window and I am looking for some advice. Currently the code I have creates a window (Toplevel) where the login controls are and I am running that using a main loop for the window. Don't do this, it is frought with difficulties. Have a single mainloop for the program. Everything else should be driven by events. So you initialise your program including creating both the main and login windows. You show the login window. When the user logs in you validate the login and if not valid return control to the login window. If it is valid close the login window and show the main window. You then proceed to process all events for the main window. Trying to synchronize and control multiple mainloops in a GUI environment is incredibly hard to get right. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Nov 1, 2011, at 12:47, Chris Hare ch...@labr.net wrote: I am working on a python Tk program which involves a login window and I am looking for some advice. Currently the code I have creates a window (Toplevel) where the login controls are and I am running that using a main loop for the window. The root window is hidden. The objective is that when the user ha successfully authenticated, the login window is closed or the main loop os exited and then the root window is shown and the main loop started for the actual application. Questions: 1. Is this the best way of doing this or is there a better way? 2. How do I exit the main loop when the user has authenticated? Thanks Chris Hare ch...@labr.net Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01/11/11 18:09, Alexander Etter wrote: Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. That depends entirely on how the user is authenticated. (assuming basic things like blanked password fields in the UI etc) For all we know the authentication could be against a central Single Sign On authentication server someplace. The OP didn't say. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
Here is a code snippet I have pulled out of the project. It is as bare bones as I can make it to get the point across. the problems I am having: 1. I would really like the window to be centered in the user's screen, but setting the geometry doesn't place it there. (that isn't included here) 2. When I click the Login button, nothing happens. I know I am missing something but it just isn't obvious what it is. 3. Finally, I would like to be able to hide the root window until the authentication is performed, but root.hide() gets me a getattr error. root.withdraw() works, but I can't get the root window back Thanks for your help. import sys from Tkinter import * import tkMessageBox import tkFont class Login: def __init__(self,parent): self.window = parent def show(instance): window = Toplevel() frame = Frame(window,bg=backColor) menubar = Menu(window) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label=Exit, command=sys.exit()) menubar.add_cascade(label=File, menu=filemenu) window.config(menu=menubar) programName = Label(frame, text = test) list = Listbox(frame) list.insert( END,test) label1 = Label(frame, text = Organization, fg=Blue, bg=backColor) label2 = Label(frame, text = Username, fg=Blue, bg=backColor) label3 = Label(frame, text = Password, fg=Blue, bg=backColor) login_userid = Entry(frame,bg=outFocusColor) login_passwd = Entry(frame,bg=outFocusColor,show=*) login_userid.bind(Return, login_passwd.focus_set()) btnLogin = Button(frame, text=Login, command=print button pressed,highlightbackground=backColor) frame.title = Login to application list.focus_set() frame.grid() programName.grid(row=0, column=0,columnspan=5,sticky=W) label1.grid(row=1, column=0,columnspan=3, sticky=W) list.grid(row=1, column=6, columnspan=5, sticky=W) label2.grid(row=2, column=0,columnspan=3, sticky=W) login_userid.grid(row=2, column=6, columnspan=5,sticky=W) label3.grid(row=3, column=0,columnspan=3, sticky=W) login_passwd.grid(row=3, column=6, columnspan=5,sticky=W) btnLogin.grid(row=4, column=4, sticky=W) if __name__ == __main__: backColor = Gray entryColor = Cyan okColor = Green warnColor = Red inFocusColor = Cyan outFocusColor = White root = Tk() root.withdraw() l = Login(root) l.show() root.mainloop()___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
Okay - that makes sense. The login window uses the show=* for the password field and is authenticated against a database where the passwords are encrypted. I have this working in a text only environment, just struggling to get it right for the GUI Thanks Chris Hare ch...@labr.net http://www.labr.net On Nov 1, 2011, at 1:02 PM, Alan Gauld wrote: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Tue, Nov 1, 2011 at 1:57 PM, Chris Hare ch...@labr.net wrote: Here is a code snippet I have pulled out of the project. It is as bare bones as I can make it to get the point across. the problems I am having: 1. I would really like the window to be centered in the user's screen, but setting the geometry doesn't place it there. (that isn't included here) Take a look at the winfo_screenwidth/height methods. 2. When I click the Login button, nothing happens. I know I am missing something but it just isn't obvious what it is. In your code you have print button pressed as the command - this is a string, and certainly wont do anything useful - you want to put a function here, e.g. command=self.login or something to that effect. You don't want parenthesis, or it will try to login as soon as python creates your button. 3. Finally, I would like to be able to hide the root window until the authentication is performed, but root.hide() gets me a getattr error. root.withdraw() works, but I can't get the root window back root.deiconify() is the method you're looking for here. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01/11/11 18:57, Chris Hare wrote: Here is a code snippet I have pulled out of the project. It is as bare bones as I can make it to get the point across. I think you could have dropped a lot more to be honst - like all the menu code for a start... 1. I would really like the window to be centered in the user's screen, but setting the geometry doesn't place it there. (that isn't included here) OK, But thats a problem for another day. And some of these things are OS/UI dependent so you need to tell us what OS you are on. 2. When I click the Login button, nothing happens. I know I am missing something but it just isn't obvious what it is. You don't provide a command in the command parameter. You provide a string. When you click the button Python will try to call the string, which won't work. You should get an error message in the console -= how are you running this? Is it from a command prompt? If not you may not be seeing all the error messages Python is sending you... 3. Finally, I would like to be able to hide the root window until the authentication is performed, but root.hide() gets me a getattr error. root.withdraw() works, but I can't get the root window back Really? You want the Login window to disappear even before you have authenticated the user? Thats very unusual behaviour. Usually the login window only goes away once you have been authenticated. import sys from Tkinter import * import tkMessageBox import tkFont class Login: def __init__(self,parent): self.window = parent def show(instance): window = Toplevel() frame = Frame(window,bg=backColor) ... label2 = Label(frame, text = Username, fg=Blue, bg=backColor) label3 = Label(frame, text = Password, fg=Blue, bg=backColor) login_userid = Entry(frame,bg=outFocusColor) login_passwd = Entry(frame,bg=outFocusColor,show=*) login_userid.bind(Return, login_passwd.focus_set()) btnLogin = Button(frame, text=Login, command=print button pressed,highlightbackground=backColor) you need to provide the name of a function to the command parameter - or use a lambda expression if its just a one liner frame.grid() label2.grid(row=2, column=0,columnspan=3, sticky=W) login_userid.grid(row=2, column=6, columnspan=5,sticky=W) label3.grid(row=3, column=0,columnspan=3, sticky=W) login_passwd.grid(row=3, column=6, columnspan=5,sticky=W) btnLogin.grid(row=4, column=4, sticky=W) if __name__ == __main__: root = Tk() root.withdraw() l = Login(root) l.show() root.mainloop() HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 11/01/2011 02:18 PM, Alan Gauld wrote: On 01/11/11 18:09, Alexander Etter wrote: Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. That depends entirely on how the user is authenticated. (assuming basic things like blanked password fields in the UI etc) For all we know the authentication could be against a central Single Sign On authentication server someplace. The OP didn't say. Question, once the code is compiled to a binary, can someone inject code to cause the hidden window to show, skipping the login altogether? -- -Joel M. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
Good feedback Alan, thanks. I wasn't using the root window to hold the login form, although I suppose I could. I guess where I am stuck is the login to control displaying the login window, and hiding it to display the actual application window once the user has authenticated. Chris Hare ch...@labr.net http://www.labr.net On Nov 1, 2011, at 3:49 PM, Alan Gauld wrote: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Nov 1, 2011 4:17 PM, Joel Montes de Oca joelmonte...@gmail.com wrote: On 11/01/2011 02:18 PM, Alan Gauld wrote: On 01/11/11 18:09, Alexander Etter wrote: Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. That depends entirely on how the user is authenticated. (assuming basic things like blanked password fields in the UI etc) For all we know the authentication could be against a central Single Sign On authentication server someplace. The OP didn't say. Question, once the code is compiled to a binary, can someone inject code to cause the hidden window to show, skipping the login altogether? Technically speaking, you could do that with /any/ program in any language. Good security is hard, and some things are just not worth spending that much time on. If good security were easy then photoshop wouldn't be pirated so much. -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 11/1/2011 3:28 PM, Chris Hare wrote: Good feedback Alan, thanks. I wasn't using the root window to hold the login form, although I suppose I could. I guess where I am stuck is the login to control displaying the login window, and hiding it to display the actual application window once the user has authenticated. Chris Hare ch...@labr.net mailto:ch...@labr.net http://www.labr.net Hi Chris, Have you looked into using a Frame to hold you input fields, and then using .destroy() to remove it upon successful login? This would allow you to not have to worry about hiding windows, as you can just reuse the same root window. Im just a hobbyist, so if there are reasons not to use this approach, I'd be interested in why. Justin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01/11/11 21:28, Chris Hare wrote: Good feedback Alan, thanks. I wasn't using the root window to hold the login form, although I suppose I could. I guess where I am stuck is the login to control displaying the login window, and hiding it to display the actual application window once the user has authenticated. Thats what your command function does. So when the button is pressed your event handler authenticates the user details, if valid it closes the Login and shows the main window(which could be root...) In pseudocode: def doLogin(self): userid = idField.get() passwd = pwField.get() if self.validateUser(userid,passwd): root.show() self.window.hide() else: self.beep() # or whatever warning message you want self.logError(User authentication failed for + userid) self.idField.clear() self.pwField.clear() Then in creating the button you pass that as the command handler: btnLogin = Button(self.window, text=Login, command=doLogin) Now, when the user hits the button the doLogin function will be called. If the login is ok we show the main window and hide the login dialog. If the entry is invalid we beep, clear the fields for a retry and log an error. We could also add a count so after, say, three attempts we close the app. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01/11/11 21:15, Joel Montes de Oca wrote: Question, once the code is compiled to a binary, can someone inject code to cause the hidden window to show, skipping the login altogether? In general you don't compile Python to a binary, although tools exist that give a good approximation to that. But to inject code would need access to the source files and if you have been sensible with permissions etc that would require admin access to the machine... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 02/11/11 00:16, Justin Straube wrote: Have you looked into using a Frame to hold you input fields, and then using .destroy() to remove it upon successful login? This is a valid approach for some scenarios but its not the norm for login dialogs. They usually popup as fairly small standalone windows. But what you suggest could be done in a banner frame at the top or bottom of the main window, then either replaced or removed from the geometry. Im just a hobbyist, so if there are reasons not to use this approach, I'd be interested in why. Only user experience I think. Its usually best to make a GUI work like the other GUIs that the user is accustomed to. OTOH many web pages use the login style that you are suggesting so maybe the fashions will change for desktop apps too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
Thanks everyone for all of the help. I almost have this working. Everything is written in a class. I think I have that right, but that remains to be seen. :-) I can create the login window and get all of the controls on it. My function gets called to validate the information in the fields when the user presses the button. the function called however, can't seem to be able to get the items from the fields. I get the error like list.get(ACTIVE) doesn't have a function for get. (list was defined as a listbox.) the same is true for the other form fields. I opted to use the root window and implement a frame in it for the login. Once the login data has been validated, i can destroy the frame and reuse the window. This may or may not work ;-) I am a python newbie, biting off a big complicated chunk The class is defined: class Login: def __init__(self, parent): self.window = parent When I show the class instance, everything is displayed. My verification code, def verifyLogin(self): farmid = list.get(ACTIVE) userid = login_userid.get() login_passwd = login_passwd.get() gets called, but I get the error Exception in Tkinter callback Traceback (most recent call last): File /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py, line 1410, in __call__ return self.func(*args) File z.py, line 229, in verifyLogin farmid = list.get(ACTIVE) AttributeError: type object 'list' has no attribute 'get' When the frame controls were added, list is defined as list = Listbox(frame) What have I got messed up? I have poked around the net but I can't find anything meaningful to me. Thanks again Chris Hare ch...@labr.net http://www.labr.net On Nov 1, 2011, at 7:50 PM, Alan Gauld wrote: On 01/11/11 21:28, Chris Hare wrote: Good feedback Alan, thanks. I wasn't using the root window to hold the login form, although I suppose I could. I guess where I am stuck is the login to control displaying the login window, and hiding it to display the actual application window once the user has authenticated. Thats what your command function does. So when the button is pressed your event handler authenticates the user details, if valid it closes the Login and shows the main window(which could be root...) In pseudocode: def doLogin(self): userid = idField.get() passwd = pwField.get() if self.validateUser(userid,passwd): root.show() self.window.hide() else: self.beep() # or whatever warning message you want self.logError(User authentication failed for + userid) self.idField.clear() self.pwField.clear() Then in creating the button you pass that as the command handler: btnLogin = Button(self.window, text=Login, command=doLogin) Now, when the user hits the button the doLogin function will be called. If the login is ok we show the main window and hide the login dialog. If the entry is invalid we beep, clear the fields for a retry and log an error. We could also add a count so after, say, three attempts we close the app. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor