1

I don't have a working code at all for this, but if I wanted to take user input and store it, and then take a different input and store that to the same list (Like a site storing login information of it's members and associating it when they want to log back in) how would I do this in python? I have this short little code:

from Tkinter import *
import tkSimpleDialog
import tkMessageBox
root = Tk()
w = Label(root, text="")
w.pack()

User_info = tkSimpleDialog.askstring("User Information", "What is your name?")
def List(List_name):
    List_name = []
    List_name.append(User_info)
    return List_name
print List

yet this produces this result: function List at 0x7fdf1fa0f668

instead of (for instance) Johnny

1
  • So you want to basically store a username and password? Commented Jul 13, 2015 at 22:09

2 Answers 2

2
from Tkinter import *
import tkSimpleDialog
import tkMessageBox
root = Tk()
w = Label(root, text="")
w.pack()

print list(iter( lambda x:tkSimpleDialog.askstring("User Information", "What is your name?"),""))

will print all the names you give it until you give it no strings

Sign up to request clarification or add additional context in comments.

1 Comment

I missed the multiple names!
2

You are not calling the function so you are seeing a reference to the function, you also need to pass parameter:

print List(param) 

What you really want is to remove the parameter and just call the function:

User_info = tkSimpleDialog.askstring("User Information", "What is your name?")
def List():
    List_name = []
    List_name.append(User_info)
    return List_name
print List()

Or simply:

User_info = tkSimpleDialog.askstring("User Information", "What is your name?")
def List():
    return [List_name]
print List()

A simple example of taking and saving the input to a file, obviously real usernames and passwords would need to be stored a lot more securely:

master = Tk()
l = Label(master, text="Username")
l.pack()
 # create Entry for user
e = Entry(master)
e.pack()
l2 = Label(master, text="Password")
l2.pack()
# create Entry for pass and show * when user types their password
e2 = Entry(master,show="*")
e2.pack()
e.focus_set()

# callback function to save the username and password
def callback():
    with open("data.txt","a")as f:
        f.write("{},{}\n".format(e.get(),e2.get()))

# command set to callback when button is pressed
b = Button(master, text="Save", width=10, command=callback)
b.pack()

mainloop()

Obviously you should be verifying the user actually entered something for both and in the real word you would have to see if the username was taken etc..

7 Comments

nice much more constructive than my answer im sure :P :) +1
And how do I store this and add more to the list?
Do you actually want to take a username and password?
Yea, I wanna take username and password
Ok then there are simpler ways, I will add an example in a few minutes
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.