Program Summary
I'm making a python based text processing program. Here I am using following Tkinter widgets with following names for its GUI:
- Text widget > "text_input"
- Text widget > "text_output"
- CheckButton widget > "checkButton_tense"
- Button widget > "button_analyse"
And Now I wanted to my program to run in following sequence.
- Taking text from "text_input".
- Perform the some Basic Text Processing in some other class on clicking the "button_analyse" and show output in "text_output".
- But if "checkButton_tense" widget is clicked/checked. Then it should also perform Tense Inspection along with basic text processing, else it should only perform basic text processing.
- Above operation no. 3 should be performed after checking status of "checkButton_tense" widget on clicking the "button_analyse" and show output in "text_output"
Problem/Error
Now when I use the if statement inside the "command=lambda:" of the my Tkinter Button "button_analyse" widget to check the status of "checkButton_tense" it gives me error. I have tried to do it with many ways but it don't works.
I have tried the solution mentioned here. But when I tried any solution like this i am unable to show my text in "text_output" widget because it is inside the different python method "main_gui_layout". I have also tried many other solutions given here at stack-overflow but don't found any identical. Kindly guide me in context of above mentioned problem and following code.
Code
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)
Aucun commentaire:
Enregistrer un commentaire