У меня есть две кнопки и текстовое поле в графическом интерфейсе. Я хочу ввести текст в текстовое поле, желательно число, а затем нажать клавишу ввода или кнопку, чтобы сохранить этот текст как переменную «Q» с помощью Widget2. Затем я хочу использовать это значение в Widget1. Как мне это сделать?
Я использую Python 3.7
ОС: Win 10
def Widget1():
print("Code Not Ready")
print("Input =", Q)
def Widget2(event):
Q= Words_field.get()
print("Words = ", Q)
if __name__ == "__main__":
GUI = Tk()
GUI.title('Widgets')
GUI.configure(background="Grey")
GUI.geometry()
Label(GUI, text='Widget2').grid(row=1, column = 0)
Words_field = Entry(GUI)
Words_field.focus_set()
Words_field.bind("<Return>", Widget2)
Words_field.grid(row =1, column = 1, ipadx=70)
B1 = Button(GUI, text=' 1. Widget1 ', fg='black', bg='Light Grey', command= Widget1, height=1, width=25)
B1.grid(row=0, column=0)
B2 = Button(GUI, text=' 2. Widget2 ', fg='black', bg='Light Grey', command= Widget2, height=1, width=25)
B2.grid(row=0, column=1)
GUI.mainloop()