나는 python과 tkinter를 사용하여 초보자 용 챠트 봇을 만들고자 시도하고 있는데, 문제가 발생했다. 나는 단순화를 위해 tkinter 코드를 제외시켰다. 전체 코드가 하단에 표시됩니다.왜 함수가 아무 것도 반환하지 않습니까?
def communicate():
sent.set(HUMAN_ENTRY.get())
bottalk(response)
AI_RESPONSE.set(response.get())
print (response.get())
print(AI_RESPONSE.get())
root.update()
def bottalk(response):
if sent == 'hello':
response = 'hello recieved'
else:
response = 'hello not recieved'
return response
AI_RESPONSE = 'hellgeto'
header.pack()
sent = StringVar()
response = StringVar()
AI_RESPONSE = StringVar()
입력은 입력 박스로 이루어지며, 어느 "안녕하세요 수신"또는 "여보세요받지"에 응답하여 설정한다 bottalk 함수에 입력을 전송하는 통신 기능으로 전송되고 GUI에서 레이블을 갱신하십시오. 그러나이 작업을 수행하면 레이블이 변경되지 않고 콘솔에서 두 개의 빈 줄이 출력됩니다. 내 기능이 "hello received"또는 "hello not received"응답을 설정하지 않는 이유는 무엇입니까? 그렇다면이 기능이 인쇄되지 않거나 GUI가 업데이트되지 않는 이유는 무엇입니까?
Py-Var2를 인쇄 (AI_RESPONSE)하면 2 개의 빈 줄이 출력됩니다. 제 질문은 그 라인에 관한 것이 아닙니다. 응답 값으로 반환 때문에
from tkinter import *
import random
class App:
def __init__(self, master):
def close():
quit()
def communicate():
sent.set(HUMAN_ENTRY.get())
bottalk(response)
AI_RESPONSE.set(response.get())
print (response.get())
print(AI_RESPONSE.get())
print(AI_RESPONSE)
root.update()
def bottalk(response):
if sent == 'hello':
response = 'hello recieved'
else:
response = 'hello not recieved'
return response
AI_RESPONSE = 'hellgeto'
root.title=('GoBot')
frame = Frame(master)
frame.pack()
self.button = Button(frame,text='Send', command=communicate)
self.button.pack(side=LEFT)
self.button2 = Button(frame,text='Quit', command=close)
self.button2.pack(side=RIGHT)
header = Label(frame, text='GoBot', fg= 'blue', font = 'Times')
header.pack()
sent = StringVar()
response = StringVar()
AI_RESPONSE = StringVar()
HUMAN_ENTRY = Entry(master, bd = 5)
HUMAN_ENTRY.pack(side=RIGHT)
responselabel = Label(frame, textvariable=AI_RESPONSE, fg = 'purple', font = 'ComicSans', anchor ='s')
responselabel.pack()
root = Tk()
app = App(root)
root.mainloop()
는
스크린 샷이 아닌 일반 텍스트로 코드를 게시하십시오. – Barmar
업데이트 중 - 콘솔에서 나갈 것임 이미지 – BritishFerret
들여 쓰기가 잘못되었거나 클래스를 사용하는 것이 정말 이상한 방법입니다 (자체 없이는) – Lafexlos