import random
import time
from tkinter import *
import pyttsx3
from bs4 import BeautifulSoup as b
import requests
global URL
URL = 'https://reallanguage.club/anglijskie-slova-na-temu-zhivotnye/'
def parcer_en(url):
r = requests.get(url)
soup = b(r.text, 'html.parser')
words = soup.find_all('td', class_= 'column-1')
return [c.text for c in words]
def parcer_ru(url):
r = requests.get(url)
soup = b(r.text, 'html.parser')
words = soup.find_all('td', class_= 'column-2')
return [c.text for c in words]
tts = pyttsx3.init()
voices = tts.getProperty('voices')
tts.setProperty('voice', voices[1].id)
newVoiceRate = 125
tts.setProperty('rate',newVoiceRate)
'''
def animals():
URL = 'https://reallanguage.club/anglijskie-slova-na-temu-zhivotnye/'
return URL
def health():
URL = 'https://reallanguage.club/anglijskie-slova-na-temu-zdorove/'
return URL
def food():
URL = 'https://reallanguage.club/anglijskie-slova-na-temu-eda/'
return URL
def nature():
URL = 'https://reallanguage.club/anglijskie-slova-na-temu-priroda/'
return URL
def changer():
change = Toplevel()
change.geometry('500x800')
window.title('Приложения для изучения английских слов')
text = Label(change, text = "Выберите тему для изучения слов", font=("Arial Bold", 20))
text.place(relx=0.5, rely=0.1, anchor=CENTER)
btn_animals = Button(change, text = 'Животные', command = animals, bg = 'green', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_animals.place(relx=0.5, rely=0.9, anchor=CENTER)
btn_food = Button(change, text = 'Еда', command = food, bg = 'green', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_food.place(relx=0.5, rely=0.7, anchor=CENTER)
btn_health = Button(change, text = 'Здоровье', command = health, bg = 'green', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_health.place(relx=0.5, rely=0.5, anchor=CENTER)
btn_nature = Button(change, text = 'Природа', command = nature, bg = 'green', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_nature.place(relx=0.5, rely=0.3, anchor=CENTER)
change.mainloop()
'''
def next():
word.configure(text = randomer())
def trans():
word.configure(text = ru_word())
def learn():
word.configure(text = randomer())
my_list()
def voice():
tts.say(en_word())
tts.runAndWait()
window = Tk()
window.title('Приложения для изучения английских слов')
word = Label(window, text = "Место для слов", font=("Arial Bold", 50))
word.place(relx=0.5, rely=0.5, anchor=CENTER)
window.geometry('1200x600')
btn_next = Button(window, text = 'Знаю', command = next, bg = 'green', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_next.place(relx=0.85, rely=0.9, anchor=CENTER)
btn_trans = Button(window, text = 'Перевод', command = trans, bg = 'blue', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_trans.place(relx=0.15, rely=0.9, anchor=CENTER)
btn_learn = Button(window, text = 'Учить', command = learn, bg = 'blue', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_learn.place(relx=0.5, rely=0.9, anchor=CENTER)
btn_voice = Button(window, text = 'озвучить', command = voice, bg = 'pink', fg = 'white', width = 10, font=("Arial Bold", 20))
btn_voice.place(relx=0.5, rely=0.7, anchor=CENTER)
def randomer():
global rand_int
rand_int = random.randint(0, len(parcer_en(URL)) - 1)
return parcer_en(URL)[rand_int]
def ru_word():
return parcer_ru(URL)[rand_int]
def my_list():
pass
def trash(words):
pass
def en_word():
return parcer_en(URL)[rand_int]
window.mainloop()
Вот код и ошибка к нему:
spoilerException in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\Админ\Dropbox\ПК\Desktop\python\words_on_py.py", line 70, in learn
word.configure(text = randomer())
File "C:\Users\Админ\Dropbox\ПК\Desktop\python\words_on_py.py", line 94, in randomer
rand_int = random.randint(0, len(parcer_en(URL)) - 1)
File "C:\Users\Админ\Dropbox\ПК\Desktop\python\words_on_py.py", line 11, in parcer_en
r = requests.get(url)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Админ\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 501, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Не понял из-за чего она, потому что пару мгновений назад все работало