-2

I have a program that does automation by logging to the devices using netmiko library. Tkinter is the front end to provide details like Device getting connected to Username and password. If I keep all the things in a single program it works.

Now I want tkinter GUI program to call program separately using import function. By doing so I want to pass values retried from GUI frontend to backend program to do some function. Where I got stuck is some values that need to pass are inside the backend function collected from frontend GUI.

Seems after import the program its not working, any help would be appreciated.

e1 e2 and e3 values are not passing under show_entry_details function created in separate python file which i imported.

''' the code is regarding tkinter application which works at the front end to prompt user for some info, which later passes to other program to call some function.'''        

# Head of Tkinter application
    master = Tk()
    master.title("Network Automation")

    # configuration for the labels and entry
    Label(master, text="Device   :  ").grid(row=0)
    Label(master, text="User ID  : ").grid(row=1)
    Label(master, text="Password : ").grid(row=2)

    e1 = Entry(master)
    e2 = Entry(master)
    e3 = Entry(master, show='*')

    e1.grid(row=0, column=1)
    e2.grid(row=1, column=1)
    e3.grid(row=2, column=1, )

    # configuration for the button
    Button(master, text='Quit', command=master.destroy).grid(row=4, column=0, sticky=W, pady=4)
    Button(master, text='Harden', command=show_entry_fields).grid(row=4, column=1, sticky=W, pady=4)



    mainloop()
Mike - SMT
  • 14,784
  • 4
  • 35
  • 79

1 Answers1

0

To pass arguments to a button's command, you can use a lambda expression:

button = Button(master, 
                text='Harden', 
                command=lambda: show_entry_fields(e1.get(), e2.get(), e3.get()))
button.grid(row=4, column=1)
Josselin
  • 2,593
  • 2
  • 22
  • 35
  • This is the error i am gettin now.Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1540, in __call__ return self.func(*args) File "/home/firdous/PycharmProjects/PythonMasterClass/gui.py", line 29, in command=lambda: show_entry_fields(e1.get(), e2.get(), e3.get())) TypeError: show_entry_fields() takes no arguments (3 given) – firdous ahmed reshi Aug 01 '17 at 18:46
  • thanks a ton... it worked but a slight doubt i am having. 1. error: /usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141: FutureWarning: CTR mode needs counter parameter, not IV self._cipher = factory.new(key, *args, **kwargs) 2. master.destroy = Quit from Gui how to destroy master since again it is under def show_entry_fields() – firdous ahmed reshi Aug 01 '17 at 19:17
  • @firdous, I don't know for point 1 but for point 2, you can pass `master` as a 4th argument in show_entry_fields(...). Finally, please [accept the answer](https://meta.stackexchange.com/a/5235) if it fixed your problem ;) – Josselin Aug 01 '17 at 19:40