Как правильно обращаться к переменным в методах класса, если эти переменные объявлены как глобальные в моем проекте?
Как это исправить? Спасибо за помощь.
main.py:
from PyQt5 import QtWidgets
import Time_code
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton
from PyQt5.QtCore import QSize
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import speech_recognition as sr
import sys
Mood_Text_Fell = ("How are you?")
mic_Text = ("MIC123")
mic_Text_1 = ("MIC123")
mic_Text_2 = ("MIC123")
Acc_Name = ("NovAndr")
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setWindowTitle("Well")
self.setFixedSize(185, 259)
self.Micro_Button = QtWidgets.QToolButton(self)
self.Micro_Button.setGeometry(55, 79, 74, 129)
self.Micro_Button.clicked.connect(self.start_microphone)
self.Settings_Button = QtWidgets.QToolButton(self)
self.Settings_Button.setGeometry(149, -1, 37, 37)
self.Account_Button = QtWidgets.QToolButton(self)
self.Account_Button.setGeometry(-1, -1, 37, 37)
self.Mood_Text = QtWidgets.QLabel(self)
self.Mood_Text.setText(Mood_Text_Fell)
self.Mood_Text.setGeometry(37, 222, 111, 18)
self.Mood_Text.adjustSize()
self.Account_Name = QtWidgets.QLabel(self)
self.Account_Name.setText(Acc_Name)
self.Account_Name.setGeometry(40, 18, 111, 18)
def start_microphone(self):
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
audio = r.listen(source)
if mic_Text == "MIC123":
mic_Text = r.recognize_google(audio, language="ru-RU")
self.Mood_Text.setText(mic_Text)
self.Mood_Text.setGeometry(18, 222, 37, 18)
elif mic_Text_1 == "MIC123":
mic_Text_1 = r.recognize_google(audio, language="ru-RU")
self.YourMessage1 = QtWidgets.QToolButton(self)
self.YourMessage1.setText(mic_Text_1)
self.YourMessage1.setGeometry(55, 222, 37, 18)
elif mic_Text_2 == "MIC123":
mic_Text_2 = r.recognize_google(audio, language="ru-RU")
self.YourMessage2 = QtWidgets.QToolButton(self)
self.YourMessage2.setText(mic_Text_2)
self.YourMessage2.setGeometry(92, 222, 37, 18)
else:
print("")
def application():
app = QApplication(sys.argv)
window = Window()
app.setWindowIcon(QtGui.QIcon('My_project.png'))
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
application()