
开篇寄语
伯衡君此前介绍了一个有关python出错就能找到答案,而且输入词条查询可以找到很多答案的python库,具体可以参看下方的前情提要,而之所以简单建立这个图形界面,一是为了练手,而是为了方便,不用每次输入命令了,制作好了,也就分享给大家咯。
前情提要
内容详情
伯衡君这次还是引用了tkinter这个python库,以及sotrace这个专门为stackoverflow打造的库,不是很难。伯衡君使用的是Windows电脑,自然生成了exe程序,如果使用其他系统,利用同样的代码可以生成该系统使用的程序。
from tkinter import *
from sotrace import get_links
root = Tk()
root.iconbitmap('./logo.ico')#You can remove this line
answer_get = StringVar()
win_width = 800
win_height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
start_x = int(screen_width / 2 - win_width / 2)
start_y = int(screen_height / 2 - win_height / 2)
def navigator():
root.title("Stackoverflow Answers Gui")
root.geometry("{}x{}+{}+{}".format(win_width, win_height, start_x, start_y))
root.resizable(False, False)
root.configure(bg="#EC882E")
def heading():
text = "You Can Know Everything"
font = ("Microsoft YaHei", 18, "bold")
head_label = Label(root, text=text, font=font, fg="#000000", bg="#EC882E", pady=20)
head_label.pack()
def your_question():
text = "Your Questions:"
font = ("Microsoft Yahei", 10, "bold")
question_label = Label(root, text=text, font=font, fg="#000000", bg="#EC882E")
question_label.place(relx=0.05, rely=0.3)
def your_question_content():
font = ("Microsoft Yahei", 10, "bold")
text_content = Entry(root, width=65, textvariable=answer_get, font=font, fg="#00FF00", bg="#000000")
text_content.place(relx=0.2, rely=0.31)
def bingo_button(*args):
text = "Bingo"
font = ("Microsoft Yahei", 10, "bold")
bingo_btn = Button(root, width=6, height=1, text=text, font=font, fg="#ff0000", command=show_answer)
bingo_btn.place(relx=0.88, rely=0.3)
def show_answer_label():
text = "Select Answers:"
font = ("Microsoft Yahei", 10, "bold")
question_label = Label(root, text=text, font=font, fg="#000000", bg="#EC882E")
question_label.place(relx=0.05, rely=0.43)
def show_answer():
str = ""
for i in get_links("{}.".format(answer_get.get()), num_of_results=100):
str += i + "\n"
font = ("Microsoft Yahei", 10)
answers = Text(root, height=8, width=90, font=font, fg="#00FF00", bg="#000000")
answers.insert(END, str)
answers.configure(state="disabled")
answers.place(relx=0.05, rely=0.5)
def main():
navigator()
heading()
bingo_button()
show_answer()
your_question()
your_question_content()
show_answer_label()
root.mainloop()
if __name__ == "__main__":
main()
如何改编
可以参考伯衡君之前写的如何用python自制YouTube下载器,请点击这篇文章:
使用方法
使用起来非常简单,只需要输入想要提问的问题(仅支持英文),上面的答案不仅多,而且还很权威,非常厉害。

之后看末尾生成的这些单词,组成的就是一个问题,找到符合你需求的链接, 复制粘贴到浏览器就可以查看了。
伯衡君默认了100个搜索答案,你可以自行设定编译,如何编译为程序,请还是参看上方那篇制作YouTube下载器的文章,里面有介绍。
温馨提示
可能有人不想编译,直接用现成的,伯衡君也为大家打好了压缩包,如果有需要,可以自行下载。
- 我的微信
- 微信扫一扫加好友
-
- 我的微信公众号
- 扫描关注公众号
-





