【发布时间】:2018-11-17 19:50:34
【问题描述】:
我有一个程序,我希望当有人单击按钮时,画布图像会发生变化。我的代码如下:
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)
【问题讨论】:
-
为什么是画布图像而不是标准标签图像?
-
我明白了,感谢 Novel 提出使用标准标签图像的想法!
标签: python python-3.x tkinter python-imaging-library tkinter-canvas