0

So, I'm creating a client manager software for a local club. I'm using Python 3.5.1 and Tkinter.

Used a Notebook to nest my Frames. On my first frame I made the form to add new clients (labels and textboxes) and an "add" button at the end. Problem is that it executes the function associated with the button insted of onclick, and the button actually does nothing on click. Been searching everywhere and it seems a rare problem. Help?

StardustGogeta
  • 3,331
  • 2
  • 18
  • 32
Rodrigo F.
  • 71
  • 1
  • 5
  • Code? From what it sounds like, my guess is that you're calling the function when you set the buttons `command` keyword. i.e. you're doing `mybutton = tk.Button(..., command = function())` instead of `command=function` – Pythonista Mar 13 '16 at 04:46
  • Yes, that is basicly it How in the fk do you insert code on comments? :p – Rodrigo F. Mar 13 '16 at 04:49
  • BTN_ok = Button(Frame_add, text=" Adicionar " command=,f_adicionar_socios(var_n_socio.get(), var_nome.get(), var_filho_de.get(), var_filho_e_de.get(), var_data_nascimento.get(), var_tipo_id.get(), var_num_id.get(), var_NIF.get(), var_morada_rua.get(), var_morada_localidade.get(), var_codigo_postal.get(), var_tel_fixo.get(), var_telemovel.get(), var_email.get(), var_tipo_socio.get(), var_data_admicao.get(), var_zona.get(), var_actividade.get(), var_actividade_de.get(), var_actividade_ate.get(), var_observacoes.get())) – Rodrigo F. Mar 13 '16 at 04:50
  • lol... you really can't unless it's very short. Code should be added in question – Pythonista Mar 13 '16 at 04:50
  • but it does not work without the brackets... var_n_socio is a variable created by textvariable=var_n_socio when i create the widgets – Rodrigo F. Mar 13 '16 at 04:51
  • add problems adding the code in the question... probably just to big – Rodrigo F. Mar 13 '16 at 04:52
  • The the sample in the comment is what you are pasting, its not too big. That sample isn't even close to valid syntax so it doesn't help much. When you create a button, you should give it the function object you want called on press. it seems like you are calling the function when creating, but its hard to tell. So, use `command=f_adicionar_socios` (not calling it) instead of `command=f_adicionar_socios(blah, blah, blah)` – tdelaney Mar 13 '16 at 05:36

2 Answers2

0

From what I could decipher, as stated in comments your not setting the command properly.

If you have a function you need to set my_button = tk.Button(..., command = my_function)

If your function takes a keyword argument then you need to pass the function like so

my_button = tk.Button(...., command = lambda: function(argument))
Pythonista
  • 11,377
  • 2
  • 31
  • 50
-1

I would try using lambda: before the command.

For instance, replace readFile(file) with lambda: readFile(file).

This will ensure an anonymous ("lambda") function with no parameters is passed, which upon execution will run the intended code. Otherwise, the function is executed once when the behavior is set, then the returned value is simply re-evaluated every time rather than the appropriate function being called.

StardustGogeta
  • 3,331
  • 2
  • 18
  • 32