There is a button:

but1 = Button(icon, text="Show the solution...", font="Arial 14", command=show) but1.grid(column=1, row=3) 

And there is an event handler when you click on it:

 def show(): lf = LabelFrame(icon, text="Solution", font='Arial 12') lf.grid(column=0, row=5, columnspan=4) Label(lf, text='1) A - B = {f1}\n' '2) B & A = {f2}\n' '3) (A - B) | (B & A) = {f3}\n' '4) ( (A - B) | (B & A) ) \ (C | B) = {rez}\n' 'Result: {rez}' .format(f1=log_oper.difference(self.A, self.B), f2=self.B & self.A, f3=(log_oper.difference(self.A, self.B))|(self.B&self.A), rez=initeq.initial_eq(self.A,self.B,self.C),font='Arial 14', justify=LEFT)).grid(column=0, row=5, sticky=W, columnspan=4) 

The LabelFrame is created in the LabelFrame window with the text:

 '1) A - B = {f1}\n' '2) B & A = {f2}\n' '3) (A - B) | (B & A) = {f3}\n' '4) ( (A - B) | (B & A) ) \ (C | B) = {rez}\n' 'Result: {rez}' 

And here is the question: How to make it so that when you click on a button, it is displayed step by step one item from that text? It can be either automatically or press the button 5 times.

  • What is log_oper ? Why not just self.A - self.B instead of log_oper.difference() ? - insolor
  • @insolor it doesn’t matter much - Artem Aleksandrovich
  • Usually it matters. Why make it difficult if you can do it simply? - insolor
  • You are right, but this does not solve my problem - Artem Aleksandrovich
  • one
    Answer vadim vaduha solves your problem, you just need to add format. - insolor

2 answers 2

 import tkinter import random class Main(tkinter.Tk): def __init__(self): super().__init__() lf = tkinter.LabelFrame(text="Solution") lf.grid() self.label_1 = tkinter.Label(lf, text='') self.label_2 = tkinter.Label(lf, text='') self.label_3 = tkinter.Label(lf, text='') self.label_4 = tkinter.Label(lf, text='') self.label_5 = tkinter.Label(lf, text='') self.button = tkinter.Button(self, text='Нажать', command=self.check).grid() self.button_remove = tkinter.Button(self, text='удалить', command=self.remove).grid() self.number_random() def check(self): if self.label_1["text"] == "": self.label_1["text"] = "1) %d - %d = %d" % (self.A, self.B, self.A - self.B) self.label_1.grid() elif self.label_2["text"] == "": self.label_2["text"] = "2) %d & %d = %d" % (self.B, self.A, self.B & self.A) self.label_2.grid() elif self.label_3["text"] == "": self.label_3["text"] = "3) (%d - %d) | (%d & %d) = %d" % (self.A, self.B, self.B, self.A, (self.A - self.B) | (self.B & self.A)) self.label_3.grid() elif self.label_4["text"] == "": self.label_4["text"] = "4) ((%d - %d) | (%d & %d) ) \ (%d | %d) = %d" % \ (self.A, self.B, self.B, self.A, self.C, self.B, ((self.A - self.B) | (self.B & self.A))/(self.C | self.B)) self.label_4.grid() elif self.label_5["text"] == "": self.label_5["text"] = "Result: %s" % str(((self.A - self.B) | (self.B & self.A))/(self.C | self.B)) self.label_5.grid() self.after_cancel() self.after(1000, self.check) def remove(self): if self.label_1["text"] != "": self.label_1.grid_remove() self.label_1["text"] = "" elif self.label_2["text"] != "": self.label_2.grid_remove() self.label_2["text"] = "" elif self.label_3["text"] != "": self.label_3.grid_remove() self.label_3["text"] = "" elif self.label_4["text"] != "": self.label_4.grid_remove() self.label_4["text"] = "" elif self.label_5["text"] != "": self.label_5.grid_remove() self.label_5["text"] = "" self.number_random() self.after_cancel() self.after(1000, self.remove) def number_random(self): self.A = random.randrange(0, 1000) self.B = random.randrange(0, 1000) self.C = random.randrange(0, 1000) if __name__ == '__main__': main = Main() main.mainloop() 
     import tkinter Text = ''' 1) A - B = {f1} 2) B & A = {f2} 3) (A - B) | (B & A) = {f3} 4) ( (A - B) | (B & A) ) \ (C | B) = {rez} Result: {rez}''' def show(iter_text, parent): '''Пошаговое создание Label's в окне LabelFrame, нажимая на кнопку''' text = next(iter_text, '') if text: tkinter.Label(parent, text=text).pack() if __name__ == '__main__': root = tkinter.Tk() # выводилось пошагово по одному пункту i_text = iter(filter(bool, map(str.strip, Text.split('\n')))) but1 = tkinter.Button(text="Show the solution...", command=lambda: show(i_text, parent=lf)) lf = tkinter.LabelFrame(text="Solution") but1.pack() lf.pack() root.mainloop() 
    • The answer is working, you only need to add format so that values ​​are displayed, something like this: i_text = iter(filter(bool, map(str.strip, Text.format(...).split('\n')) - insolor
    • since I have a set() , so split is not suitable for them - Artem Aleksandrovich