How To Get Multiple Text Entries From Gui And Use Those In A Main Python Script?
I have a python file that extracts tweets, get their geo-coordinates and sentiment and finally plots those tweets/sentiment as colored circles on a map. The following inputs (text
Solution 1:
You could store the results of the different GUI 'questions' in to a dictionary ready for the other parts of the code to use. That way you would only have one function that 'collects/validates/stores' the responses.
For example
import tkinter as tk
classApp(tk.Frame):
def__init__(self,master=None,**kw):
#Create a blank dictionary
self.answers = {}
tk.Frame.__init__(self,master=master,**kw)
tk.Label(self,text="Maximum number of Tweets").grid(row=0,column=0)
self.question1 = tk.Entry(self)
self.question1.grid(row=0,column=1)
tk.Label(self,text="Topic").grid(row=1,column=0)
self.question2 = tk.Entry(self)
self.question2.grid(row=1,column=1)
tk.Button(self,text="Go",command = self.collectAnswers).grid(row=2,column=1)
defcollectAnswers(self):
self.answers['MaxTweets'] = self.question1.get()
self.answers['Topic'] = self.question2.get()
functionThatUsesAnswers(self.answers)
deffunctionThatUsesAnswers(answers):
print("Maximum Number of Tweets ", answers['MaxTweets'])
print("Topic ", answers['Topic'])
if __name__ == '__main__':
root = tk.Tk()
App(root).grid()
root.mainloop()
When the button is pressed, each of the 'answers' are added to a dictionary which is then passed to the function that does the main part of your code.
Post a Comment for "How To Get Multiple Text Entries From Gui And Use Those In A Main Python Script?"