【发布时间】:2018-04-30 14:33:47
【问题描述】:
我有一个 python 文件,它可以提取推文,获取它们的地理坐标和情绪,最后将这些推文/情绪绘制为地图上的彩色圆圈。
需要以下输入(文本条目)才能使其工作: 每个输入提示旁边还会显示一个示例用户输入:
Enter the maximum number of tweets: *100*
Do you want to search by topic? type: y or n: *y*
Enter topic: *MoSalah*
Enter visulaization/projection type:
1. Mercator
2. orthographic
3. melloweide
>> *Mercator*
Zoom in to a conteninent of choice:
1. world
2. africa
3. asia
4. north america
5. south america
6. europe
7. usa
>> *world*
Enter symbol shape:
1. square
2. circle
>> *circle*
现在,为了让用户体验更令人兴奋,我想构建一个简单的 GUI,询问用户所有这些输入并将它们存储到各自的变量中,但我不知道如何创建一个更重要的是将 GUI 链接到它背后运行的 python 代码。
我是否必须为上面显示的每个必需输入提供单独的检索功能? 例如,这就是最大编号的检索功能。推文应该看起来像使用 tkinter GUI:
from tkinter import *
root = Tk()
root.geometry('200x100')
# Retrieve to get input form user and store it in a variable
# Retrieve maximum number of tweets
def retrieveMaxTweets():
maxTweets = textBox.get()
return maxTweets
textBox = Text(root, height = 2, width = 10)
textBox.pack()
buttonComment = Button(root, height=1, width=10, text='Enter max no. of tweets', command = lambda: retrieveMaxTweets())
buttonComment.pack()
mainloop()
然后在我最初要求限制的代码部分中,我这样做:
limit = retrieveMaxTweets()
而不是这个:
limit = int(input(" Enter the maximum number of tweets: "))
【问题讨论】:
-
您可以将不同 GUI“问题”的结果存储到字典中,以供代码的其他部分使用。这样,您将只有一个“收集/验证/存储”响应的功能。
标签: python-3.x user-interface tkinter sentiment-analysis text-widget