我有一个程序,我想当有人点击一个按钮,画布图像将改变。我的代码如下:
from PIL import ImageTk,Image, ImageFont, ImageDraw
import tkinter
import textwrap
from tkinter import Frame, Canvas, Text, INSERT, END
root = tkinter.Tk()
root.geometry("296x337")
root.resizable(False, False)
im=Image.open("red.jpg")
photo=ImageTk.PhotoImage(im)
cv = tkinter.Canvas()
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(0, 0, image=photo, anchor='nw')
def changepic():
###place where I want to change the Canvas Image
print("change color")#I added this because python wouldn't let me run thee function without something.
a2=tkinter.Button(root,text='change color',bd=0, command=changepic)
a2.config(highlightbackground='black')
a2.place(x=135, y=70)
我没有使用Canvas,而是替换了代码,以便它使用tkinter.标签公司名称:
我的信息来自:How to update the image of a Tkinter Label widget?
和:https://www.tutorialspoint.com/python/tk_label.htm
相关问题 更多 >
编程相关推荐