python - 当我运行代码时,PRAW 连接的 Tkinter GUI 显示为空白
问题描述
我正在编写一个连接到 reddits API 的程序。我为用户设置了三个条目小部件,以输入特定的单词、特定的 subreddit 和要解析的特定帖子数。
下面贴出代码。我将所有这些都放在一个名为 KDGUI 的类中。当我运行脚本时,我只是得到一个空白的白色 Tkinter GUI 屏幕。
有任何想法吗?我试过在课堂上来回切换 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()
解决方案
推荐阅读
- vue.js - 基于数据属性的动态类
- c++ - C++:灵活且能够存储多种数据类型的数组
- vue.js - 如何在模板中获取 vuetify 数字类型 v-text-field 的值
- cordova - 无法打开现有的 Cordova 项目
- python - 如何在 jupyter hub 的帐户中运行烧瓶?
- batch-file - 如何在 Windows 上的批处理脚本中附加/连接变量
- ansible - 使用 find (ansible) 模块读取多数组
- excel - 在 excel 中列出超过 9 个值列表的所有可能组合
- selenium - 无法选择下拉菜单,预期条件失败:等待由 id 定位的元素的可见性
- c - 二维数组的输入(-1 表示行结束输入,-2 表示二维数组输入结束)问题