Function being called before being called by GUI

Asked

Viewed 35 times

0

I have a software that I am using Tkinter as GUI, to receive some parameters that the user will pass me.

In this software I have 1 problem and a doubt.

the problem is this, just when I run the software the process_files function is already executed, and I wanted it to be executed only when I clicked the button.

and the other problem is how can I pass my variavel farm_name and one of the options selected in OptionMenu for my job process_files?, I tried to send it as a parameter, but it doesn’t work.

from Tkinter import *
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog

window = Tk()


def process_files():
  #logic here.


#interface
farm_variable = StringVar()
farm_label = Label(window, text='Nome: ').pack()
farm_name = Entry(window, textvariable=farm_variable).pack()

year_label = Label(window, text='Ano: ').pack()
default_value = StringVar(window)
default_value.set(2018)

OptionMenu(window, default_value, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010).pack()

button_2 = Button(window, text='Processar')
button_2.bind("<Button-2>", process_files())
button_2.pack(side=RIGHT)


window.mainloop()
  • button_2.bind("<Button-2>", process_files()), you are calling the function here

  • It’s not the idea that you would dream when I clicked on button 2?

  • 1

    Take the parentheses, just leave button_2.bind("<Button-2>", process_files)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.