Я пишу программу, которая подключается к Reddits API. У меня есть три виджета ввода, настроенные для ввода пользователем определенного слова, определенного субредита и определенного количества сообщений для анализа.
Ниже приведен код. У меня все это сидит в классе под названием KDGUI. Когда я запускаю скрипт, я просто получаю пустой белый экран графического интерфейса Tkinter.
Есть идеи? Я пробовал вкладывать код GUI взад и вперед в классе. Я не достаточно опытен, чтобы действительно понять это.
Спасибо!
Это на возвышенном тексте. Я не опубликовал информацию об API, но представьте, что она выше корневой переменной.
root = tk.Tk()
Ht = 300
Wd = 450
class KDGUI():
def enter_info():
word = e1.get()
subred = e2.get()
amnt = e3.get()
def run_bot():
sub = r.subreddit(subred)
time.sleep(1)
print("---Grabbing subreddit---\n")
time.sleep(1)
subs = sub.top('day', limit=amnt)
print("---Grabbing posts in sub---\n")
time.sleep(1)
print("Looking for Articles..\n")
word_not_found = True
for posts in subs:
article_url = posts.url
post_title = posts.title
word_to_find = word
word_not_found = False
if word_to_find in post_title:
time.sleep(3)
print(post_title)
print('')
else:
word_not_found = word_not_found and True
if word_not_found:
print("Can't find articles in the subreddit!")
root.title("Finding Kawhi Articles")
canvas = tk.Canvas(root, height=Ht, width=Wd)
canvas.pack()
background_image = tk.PhotoImage(file='Kawhi-Leonard.gif')
background_label = tk.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
e1 = tk.Entry(root) # Word to enter
e1.place(relx=.275, rely=.45)
e2 = tk.Entry(root) # subreddit to enter
e2.place(relx=.275, rely=.55)
e3 = tk.Entry(root) # sort by amount of posts
e3.place(relx=.275, rely=.65)
activate_button = tk.Button(root, text="Click here to generate
article!", command=run_bot)
activate_button.place(relx=.20, rely=.85, relwidth=0.55,
relheight=0.10)
close_button = tk.Button(root, text="Click to close program",
command = root.quit)
close_button.place()
root.resizable(False, False)
root.mainloop()
KDGUI()