Я использую Tkinter в качестве графического интерфейса для создаваемого настольного приложения.я получаю ту же ошибку
from tkinter import Tk
import sys
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import messagebox
import schedule
import time
from Tweets import Tweets
class MyFirstGUI:
def __init__(self):
pass
def masterframe(self, master, ):
master = master
master.title("A simple Sentiment Analyzer")
_bgcolor = '#4285F4' # X11 color: 'gray85'
_fgcolor = '#e3f2fd' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
style = ttk.Style()
if sys.platform == "win32":
style.theme_use('winnative')
style.configure('.', background=_bgcolor)
style.configure('.', foreground=_fgcolor)
style.configure('.', font="Arial")
style.map('.', background=[('selected', _compcolor), ('active', _ana2color)])
master.geometry("600x450+650+150")
master.configure(background="#d9d9d9")
return master
def appframe(self, master):
tFrame1 = ttk.Frame(master)
tFrame1.place(relx=-0.017, rely=-0.067, relheight=1.078, relwidth=1.025)
tFrame1.configure(relief='groove')
tFrame1.configure(borderwidth="2")
tFrame1.configure(relief="groove")
tFrame1.configure(width=615)
return tFrame1
def headerlabel(self, tframe1):
headind_label = tk.Label(tframe1)
headind_label.place(relx=0.049, rely=0.165, height=21, width=294)
headind_label.configure(background="#4285F4")
headind_label.configure(disabledforeground="#a3a3a3")
headind_label.configure(foreground="#ffffff")
headind_label.configure(text='''Enter Keyword/Hashtag from Twitter''', font=("Helvetica Bold", 12))
def keywordlabel(self, tframe1):
key_label = tk.Label(tframe1)
key_label.place(relx=0.081, rely=0.268, height=31, width=94)
key_label.configure(background="#4285F4")
key_label.configure(disabledforeground="#a3a3a3")
key_label.configure(foreground="#ffffff")
key_label.configure(text='''Keyword''', font=("Helvetica Bold", 9))
key_label.configure(width=94)
def timeselection(self, tframe1):
time_label = tk.Label(tframe1)
time_label.place(relx=0.049, rely=0.392, height=31, width=134)
time_label.configure(background="#4285F4")
time_label.configure(disabledforeground="#a3a3a3")
time_label.configure(foreground="#ffffff")
time_label.configure(text='''Run time(hourly)''', font=("Helvetica Bold", 9))
time_label.configure(width=114)
def keyword_input(self, tframe1, ):
global key_input
key_input = tk.Entry(tframe1)
key_input.place(relx=0.276, rely=0.268, height=30, relwidth=0.234)
key_input.configure(background="white")
key_input.configure(disabledforeground="#a3a3a3")
key_input.configure(font="TkFixedFont")
key_input.configure(foreground="#000000")
key_input.configure(highlightbackground="#d9d9d9")
key_input.configure(highlightcolor="black")
key_input.configure(insertbackground="black")
key_input.configure(selectbackground="#c4c4c4")
key_input.configure(selectforeground="black")
def startbutton(self, tframe1):
start_Button = tk.Button(tframe1)
start_Button.place(relx=0.293, rely=0.515, height=24, width=35)
start_Button.configure(activebackground="#ececec")
start_Button.configure(activeforeground="#000000")
start_Button.configure(background="#ffffff")
start_Button.configure(disabledforeground="#a3a3a3")
start_Button.configure(foreground="#000000")
start_Button.configure(highlightbackground="#d9d9d9")
start_Button.configure(highlightcolor="black")
start_Button.configure(pady="0")
start_Button.configure(text='''Start''', command=self.runjob)
def stopbutton(self, tframe1):
stop_button = tk.Button(tframe1)
stop_button.place(relx=0.407, rely=0.515, height=24, width=35)
stop_button.configure(activebackground="#ececec")
stop_button.configure(activeforeground="#000000")
stop_button.configure(background="#ffffff")
stop_button.configure(disabledforeground="#a3a3a3")
stop_button.configure(foreground="#000000")
stop_button.configure(highlightbackground="#d9d9d9")
stop_button.configure(highlightcolor="black")
stop_button.configure(pady="0")
stop_button.configure(text='''Stop''', command=self.stopjob)
def combobox(self, tframe1):
global time_selection
time_selection = ttk.Combobox(tframe1)
time_selection.place(relx=0.276, rely=0.392, relheight=0.064, relwidth=0.233)
time_selection['values'] = ("1", "6", "12", "24")
time_selection.current(0) # set the selected item
time_selection.configure(takefocus="")
def frame_divider(self, tframe1):
tseparator1 = ttk.Separator(tframe1)
tseparator1.place(relx=0.545, rely=0.01, relheight=0.99)
tseparator1.configure(orient="vertical")
def job_get_tweet(self):
# api-endpoint
base_url = "http://192.168.0.7/"
tweet_word = key_input.get()
tweet = Tweets()
tweet.retrieve_tweet(base_url, tweet_word)
def job_fetch_tweet_from_db(self):
# api-endpoint
base_url = "http://192.168.0.7/"
tweet_get = Tweets()
tweet_get.get_tweet_from_db(base_url)
def runjob(self, ):
messagebox.showinfo('Tweet Scheduler', 'Tweet has been scheduled to run ' + time_selection.get() + ' hours')
schedule.every(int(time_selection.get())).hour.do(self.job_get_tweet())
# schedule.every(1).minutes.do(job_fetch_tweet_from_db)
# schedule.every( ).day.at("10:30").do(job)
# schedule.every(5).to(10).minutes.do(job)
# schedule.every( ).monday.do(job)
# schedule.every( ).wednesday.at("13:15").do(job)
# schedule.every( ).minute.at(":17").do(job)
running = True
while running:
schedule.run_pending()
time.sleep(1)
def stopjob(self):
print('job stopped')
root = Tk()
my_gui = MyFirstGUI()
username = tk.StringVar()
# calling the master frame method to create the master window
master_frame = my_gui.masterframe(root)
# calling the application frame to pack all widgets
app_frame = my_gui.appframe(master_frame)
# calling the first label widget method to display the label
my_gui.headerlabel(app_frame)
# calling the keyword label method to display the label widget
my_gui.keywordlabel(app_frame)
# calling the time selection label method to display the label widget
my_gui.timeselection(app_frame)
# calling the text entry widget in the frame
my_gui.keyword_input(app_frame)
# calling the timeslot selection widget in the frame
my_gui.combobox(app_frame)
# calling the start button widget to fire an action
my_gui.startbutton(app_frame)
# calling the stop button widget to fire an action to stop all running instances
my_gui.stopbutton(app_frame)
# calling frame vertical seperator
my_gui.frame_divider(app_frame)
# displays all widgets used fro the tkinter library
root.mainloop()
Я ожидаю, что твиты будут сохранены в моей базе данных mongodb, но продолжаю получать
Исключение в обратном вызове Tkinter (последний вызов в последний раз): Файл "C: \ Users \ cybor \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ urllib3 \ connection.py ", строка 159, в _new_conn (self._dns_host, self.port), self.timeout, ** extra_kw)
Есть идеи, как это исправить?