1

I am a beginner and I am aware that I must not be following proper coding procedure. I have all my functions in one file and I have been passing four parameters to this file, but i really need user input. I cannot figure out how to get four parameters from the user. I added the recommendations from the user , but I still do not get the data that I am looking for

I am using Winpython 2.7.5.

I would like to get three Strings which works in a standalone version as posted here on stackoverflow. How do I print and have user input in a text box in tkinter, Python 3.2.5?

then I would like the user to open a file dialog box and pick a text file, similar to filedialog, tkinter and opening files

if I use the code below, then I can not access the returned values for the file name

import Tkinter, tkFileDialog

def myDialog():
    root = Tkinter.Tk()
    results = []

    label1 = Tkinter.Label( root, text="Header")
    E1 = Tkinter.Entry(root, bd =5)

    label2 = Tkinter.Label( root, text="Machine Name")
    E2 = Tkinter.Entry(root, bd =5)

    label3 = Tkinter.Label( root, text="final filename")
    E3 = Tkinter.Entry(root, bd =5)

    def getDate():
        results.append(E1.get())
        results.append(E2.get())
        results.append(E3.get())
        root.destroy() # close the window


    def getFile():
        results.append(tkFileDialog.askopenfilename())

    submit = Tkinter.Button(root, text ="Submit", command = getDate)
    openfiledialog = Tkinter.Button(root, text ="Open File", command = getFile)

    label1.pack()
    E1.pack()
    label2.pack()
    E2.pack()
    label3.pack()
    E3.pack()
    submit.pack(side =Tkinter.LEFT)
    openfiledialog.pack(side =Tkinter.RIGHT)
    root.mainloop() # the mainloop is used to paint the gui and react on input
    return results

checkresults = []
checkresults = myDialog
Community
  • 1
  • 1
user2565278
  • 77
  • 1
  • 7

1 Answers1

0

I think you are almost at what you wanted to do:

def myDialog():
    root = Tk()
    results = []

    label1 = Label( root, text="Header")
    E1 = Entry(root, bd =5)

    label2 = Label( root, text="Machine Name")
    E2 = Entry(root, bd =5)

    label3 = Label( root, text="final filename")
    E3 = Entry(root, bd =5)

    def getDate():
        results.append(E1.get())
        results.append(E2.get())
        results.append(E3.get())
        root.quit() # end the mainloop
        root.destroy() # close the window

    submit = Button(root, text ="Submit", command = getDate)

    label1.pack()
    E1.pack()
    label2.pack()
    E2.pack()
    label3.pack()
    E3.pack()
    submit.pack(side =BOTTOM)
    root.mainloop() # the mainloop is used to paint the gui and react on input
    return results

This myDialog opens the dialog you programed and closes it on submit.

User
  • 14,131
  • 2
  • 40
  • 59
  • hi, Thanks for taking the time, but I do not get anything from the function returned. – user2565278 Feb 20 '14 at 21:10
  • This may be because you closed the window without pushing the submit button. It that the case? – User Feb 20 '14 at 21:15
  • no, I click submit and check the variable and I have values for the 3 text fields, but nothing for the fileopen tab. is it possible that it is related to Winpython – user2565278 Feb 20 '14 at 21:49
  • I removed the file open thing. You can still put it in somewhere. I thought since these are two dialogs: now you call `checkresults = myDialog()` and after this `filename = tkFileDialog.askOpenFileName()` – User Feb 20 '14 at 22:11