I'm trying to build an AI with tkinter, but i've one problem. I've done a test but the it seems like the input_get variable doesn't change. When I call the variable in the function it work but if I call it outside it doesn't. Have you some advices ? (It's just a part of the code, the frame, the input field (Entry),etc are already put)
from tkinter import *
from tkinter import font
ia_answers = ""
input_get = ""
window = Tk()
window.config(cursor="wait")
input_frame = LabelFrame(window, text="User :", borderwidth=4)
input_frame.pack(fill=BOTH, side=BOTTOM)
input_user = StringVar()
input_field = Entry(input_frame, text=input_user)
input_field.pack(fill=BOTH, side=BOTTOM)
ia_frame = LabelFrame(window, text="Discussion",borderwidth = 15, height = 200, width = 200)
ia_frame.pack(fill=BOTH, side=TOP, expand = True)
printopt = font.Font(family = "Times")
text = Text(ia_frame, state='disabled', bg ="grey")
text.pack(fill = BOTH, expand = True, side = "left")
text.tag_configure("right", justify="right", font=printopt)
text.tag_configure("left", justify="left", font=printopt)
scr = Scrollbar(ia_frame)
scr.config(command=text.yview)
text.config(yscrollcommand=scr.set)
scr.pack(side="right", fill="y", expand=False)
def Enter_pressed(event):
"""Took the current string in the Entry field."""
global input_get
input_get = input_field.get()
input_user.set("")
text.configure(state='normal')
text.insert("end", "\n"+input_get+"\n", "left")
text.insert("end", "\n"+ia_answers+"\n", "right")
text.configure(state='disabled')
text.yview(END)
return input_get
def inputget(event):
if input_get == "ok":
ia_answers = "test"
input_field.bind("<Return>", Enter_pressed, inputget)
window.mainloop()
Thank you. Ilan Rossler