我想要显示一个图像并在其上绘制一个坐标系(x-ax,y-ax)。 我可以显示图像
img = ImageTk.PhotoImage(Image.open(path).resize((400,400),Image.ANTIALIAS))
panel = tk.Label(root,image = img, width = 400, height = 400s)
panel.pack(size= "bottom", fill = "both", expand = "yes")
panel.place(rely = 073, rely = 0.5s)
我还可以为x-ax / y-ax绘制一条线(如果你知道一种绘制闪光而不是直线的方法会更好)
canvas = Canvas(root)
canvas.create_line(x0,y0,x1,y1)
canvas.pack()
我不能做的是将此行放在图片顶部。我尝试使用canvas.place(),但当我把它放在图像上时,我再也看不到图像了。有没有办法让画布透明?或者我还能做些什么吗?我是Tkinter的新手。
感谢。
编辑:显然不可能使画布透明Transparent canvas in tkinter python
但是我可以在画布中添加背景图像然后绘制线条,以便我可以看到它们吗?
答案 0 :(得分:3)
您必须将图像放在画布上,然后将轴线放在它上面:
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
img_path = 'water-drop-splash.png'
img = ImageTk.PhotoImage(Image.open(img_path).resize((400,400), Image.ANTIALIAS))
canvas = tk.Canvas(root, height=400, width=400)
canvas.create_image(200, 200, image=img)
canvas.create_line(0, 200, 399, 200, dash=(2,2)) # x-axis
canvas.create_line(200, 0, 200, 399, dash=(2,2)) # y-axis
canvas.pack()
root.mainloop()
钽哒!