как мне сделать что бы с поля Entry считовался текст?
вот мой код:
class MyEntry(tk.Entry):
def __init__(self, master, x, y, *args, **kwargs):
super(MyEntry, self).__init__(master, font = 'Calibri 15 bold' ,*args, **kwargs)
self.x = x+1
self.y = y
class MineSweeper:
window = Tk()
window["bg"] = "darkorange"
ROW = 6
COLUMNS = 4
MINES = 24
def __init__(self):
self.entry = []
count = 1
cur_q = -7
facts = [
{'text': '20+3= ','right': 23},
{'text': '10-5=','right': 23},
{'text': '41-9=','right': 23},
{'text': '20*5=','right': 23},
{'text': '40/2=','right': 23},
{'text': '40+61=','right': 23},
{'text': '4+10=','right': 23},
{'text': '9+6=','right': 23},
{'text': '10*5=','right': 23},
{'text': '20+90=','right': 23},
{'text': '90-20=','right': 23},
]
for i in range(MineSweeper.ROW):
temp = []
for j in range(MineSweeper.COLUMNS):
lab = Message(text = facts[cur_q]['text'], font = ('Arial', 14), width =1000, borderwidth = 0,background="darkorange")
ent = MyEntry(MineSweeper.window,x=i, y=j, background="darkorange")
temp.append(ent)
temp.append(lab)
count +=1
if cur_q < len(facts) - 1:
cur_q += 1
lab['text'] = facts[cur_q]['text']
self.entry.append(temp)
def check():
points= 0
answer = int(ent.get())
if facts[cur_q]['right'] == answer:
points += 1
else:
points_label = Label(text = 'Вы набрали ' + str(points) + ' очка', font = ('Arial', 34), fg = 'red', bg = 'white')
points_label.place(x = 0, y = 0, width = 700, height = 250)
b = Button(text = 'Ответить', font = ('Arial', 24), fg = 'black', command=check)
b.place(x = 200, y = 130)
def create_widget(self):
for i in range(MineSweeper.ROW):
for j in range(MineSweeper.COLUMNS):
ent = self.entry[i][j+1]
ent.grid(row =i, column= j)
def start(self):
self.create_widget()
self.print_entry()
MineSweeper.window.mainloop()
def print_entry(self):
for row_entry in self.entry:
print(row_entry)
game = MineSweeper()
game.start()