2

I am writing code for a reddit bot that takes any given keyword, searches any given subreddit for that given key word, and if it finds that key word in the subreddit, pulls the title of the thread.

I have developed a GUI with Tkinter, and using the Entry widget, I want to be able to type in a given key word into the entry box, and have it be passed into my main bot function(run_bot) as the given key word when I activate the bot.

Now I have a button widget set up to execute a function (run_bot) which parses reddit when clicked. However, this executes the function(run_bot) with default key word and subreddit parameters that I already have written in the back end.

How do I get any key word that I type into the entry widget, connect to be the passed-in parameter in the run_bot function, and execute the function accordingly?

I hope I made sense. I can post code too if need be but I felt it wasn't necessary as I'm just trying to grasp the entry widget more.

Thanks

nick_rinaldi
  • 641
  • 6
  • 17

2 Answers2

1

You can bind the Enter key to the entry, and have it call run_bot, with value in entry as a parameter:

something like this:

entry.bind('<Enter>', lambda: run_bot(entry.get()))
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • Thank you! Any idea where I could have found documentation stating this online? I parsed a few sources online but, couldn't find anything about the bind method with the entry widget. Therefore I had to post here lol – nick_rinaldi Jun 21 '19 at 12:25
  • You are welcome, I am glad I could help, If you feel that my answer helped you, you could consider [what to do when someone answers my question](https://stackoverflow.com/help/someone-answers), and [how to accept my answer](http://meta.stackexchange.com/a/5235) – Reblochon Masque Jun 21 '19 at 13:56
  • Stackoverflow is a good place to find this sort of info, but the search mostly requires that you know what you are looking for. If you don't find something useful, you can ask, if there is an existing good answer, you will be directed to it. – Reblochon Masque Jun 21 '19 at 13:57
-1

My first thought would be to use a callback every time the entry gets changed. Watch this thread for more infos: How do I get an event callback when a Tkinter Entry widget is modified?

But then you execute function would be fired by every key press, I think. If you don't want this then you probably have to use a button which triggers the execute function.

mudo121
  • 54
  • 7