我正在尝试为我用python编写的twitter抓取程序制作UI。我包含了代码,并对所有建议持开放态度。
import random
from Tkinter import Tk, Label, Button, Entry, StringVar, DISABLED, NORMAL, END, W, E
class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title("Python Scraper")
self.label = Label(master, text="Please enter a hashtag (#hashtag) to search twitter for.")
self.label1.pack()
#Box to input hashtag
self.label2 = Label(master, text = "How many results would you like per search? Recommended: 200-1000.")
self.label2.pack()
#Box to enter results per search
self.label3= Label(master, text = "How many times would you like Twitter scraped? Warning: do not exceed the data cap! Recommended 6 or less times")
self.label3.pack()
#box to enter number of times to scrape twitter
self.label4 = Label(master, text = "What would you like on your x-axis?")
self.label4.pack()
#drop down box with the 5 options
self.label5 = Label(master, text = "What would you like on your y-axis")
self.label5.pack()
#dropdown box with the same five options as above
self.search_button = Button(master, text="Search", command=self.search)
#self.search_button.pack()
def search(self):
#This should take the inputs from the boxes and selections from the x and y axis and
#enter it into another program that will be pasted below. I don't want to share due to
#OAuth credentials etc..
print("Greetings!")
root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()
我在运行时遇到此错误:
Traceback (most recent call last):
File "tkkkk2.py", line 32, in <module>
my_gui = MyFirstGUI(root)
File "tkkkk2.py", line 10, in __init__
self.label1.pack()
AttributeError: MyFirstGUI instance has no attribute 'label1'
我认为发生了什么: 我认为我需要对标签做些什么。我觉得tkinter默认处理一个标签就好了,但是我需要做一些事来制作另一个标签。
下: 我不知道如何制作输入框或将这些值传递给另一个功能。 我正在运行El Capitan的macbook air,我有python 2.7。
答案 0 :(得分:1)
这看起来很简单。你有这两行:
self.label = Label(master, text="Please enter a hashtag (#hashtag) to search twitter for.")
self.label1.pack()
我认为第一行应该是这样的:
self.label1 = Label(master, text="Please enter a hashtag (#hashtag) to search twitter for.")
我们在哪里制作self.label
- &gt; self.label1