Краткое содержание программы
Я делаю программу обработки текста на основе Python. Здесь я использую следующие виджеты Tkinter со следующими именами для его GUI:
- Текстовый виджет> "text_input"
- Текстовый виджет> "text_output"
- Виджет CheckButton> "checkButton_tense"
- Виджет кнопок> "button_analyse"
И теперь я хотел, чтобы моя программа работала в следующей последовательности.
- Получение текста из "text_input".
- Выполните некоторую базовую обработку текста в каком-то другом классе, щелкнув «button_analyse» и покажите вывод в «text_output».
- Но если щелкнуть / проверить виджет "checkButton_tense". Затем он должен также выполнять проверку времени вместе с основной обработкой текста, иначе он должен выполнять только базовую обработку текста.
- Над операцией №. 3 следует выполнить после проверки состояния виджета «checkButton_tense» при нажатии кнопки «button_analyse» и показать вывод в «text_output»
Проблема / ошибка
Теперь, когда я использую оператор if внутри виджета "command = lambda:" моего виджета кнопки Tkinter "button_analyse", чтобы проверить состояние "checkButton_tense", он выдает ошибку. Я пытался сделать это многими способами, но это не работает.
Я пробовал упомянутое решение здесь . Но когда я попробовал какое-либо решение, подобное этому, я не смог показать свой текст в виджете "text_output", потому что он внутри другого метода python "main_gui_layout". Я также пробовал много других решений, приведенных здесь, при переполнении стека, но не нашел ничего идентичного Пожалуйста, направьте меня в контексте вышеупомянутой проблемы и следующего кода.
Код
from tkinter import *
from Examples import Examples
from TextAnalysis import PerformTextAnalysis
class MyGui:
useExamples = Examples()
performTextAnalysis = PerformTextAnalysis()
def __init__(self, master):
self.main_gui_layout(master)
def main_gui_layout(self, master):
# InputBox to get the input Text.
text_input = Text(master, bd=1, height=15, width=100)
text_input.insert('end', self.useExamples.example2)
text_input.pack(side=TOP)
# OutputBox to show the processed Text.
text_output = Text(master, bd=1, height=15, width=100)
text_output.pack(side=TOP)
# CheckButton: it will perform tense analysis if checked/clicked
tenseCheck_clicked = IntVar()
checkButton_tense = Checkbutton(master, text="Tense Inspection", variable=tenseCheck_clicked,
bg='#9aa7bc')
checkButton_tense.var = tenseCheck_clicked
checkButton_tense.pack(side=TOP)
# Analysis Button: it will process text and show in output.
# It will also perform Tense Analysis if Above "checkButton_tense" is check/active.
button_analyse = Button(master, text="Analyse Requirements", width=20,
command=lambda:
[
self.performTextAnalysis.get_userReqiurement(
str(text_input.get('1.0', 'end'))),
if tenseCheck_clicked == 1:
ans = self.performTextAnalysis.performBasicAnalysis(),
self.performTextAnalysis.performTenseAnalysis(),
text_output.insert(END, ans)
else:
self.performTextAnalysis.performBasicAnalysis()
])
button_analyse.pack(side=TOP)