이것은 내 첫번째 파이썬 프로그래밍 코드입니다. 클릭 한 번으로 이미지를 변경하려고합니다. 두 개의 버튼이 있습니다 대화 시작 & 대화 중지.버튼 클릭시 이미지 변경
양식로드시 이미지가 없습니다. 시작 버튼을 클릭하면 ABC 이미지가 표시됩니다. 버튼을 클릭하면 xyz 이미지가 표시됩니다.
내가 직면 한 문제는 시작을 클릭하면 해당 이미지가 나타나지만 중지를 클릭하면 새 이미지가 나타나지만 이전 이미지는 사라지지 않는다는 것입니다. 두 이미지가 다른
내 코드 뒤에 하나를 표시는 아래
root = Tk()
prompt = StringVar()
root.title("AVATAR")
label = Label(root, fg="dark green")
label.pack()
frame = Frame(root,background='red')
frame.pack()
기능 정의 가장 중요한 문제는 새로운 이미지를 만들기 전에 당신이 당신의 캔버스를 취소하지 않는 것이
def Image1():
image = Image.open("C:\Python27\Agent.gif")
photo = ImageTk.PhotoImage(image)
canvas = Canvas(height=200,width=200)
canvas.image = photo # <--- keep reference of your image
canvas.create_image(0,0,anchor='nw',image=photo)
canvas.pack()
def Image2():
image = Image.open("C:\Python27\Hydrangeas.gif")
photo = ImageTk.PhotoImage(image)
canvas = Canvas(height=200,width=200)
canvas.image = photo # <--- keep reference of your image
canvas.create_image(0,0,anchor='nw',image=photo)
canvas.pack()
#Invoking through button
TextWindow = Label(frame,anchor = tk.NW, justify = tk.LEFT, bg= 'white', fg = 'blue', textvariable = prompt, width = 75, height=20)
TextWindow.pack(side = TOP)
conversationbutton = Button(frame, text='Start Conversation',width=25,fg="green",command = Image1)
conversationbutton.pack(side = RIGHT)
stopbutton = Button(frame, text='Stop',width=25,fg="red",command = Image2)
stopbutton.pack(side = RIGHT)
root.mainloop()
으로 바꿉니다. 사용자 6829070, 대답을 확인 했습니까? 언급하십시오. –