lad*_*ads 2 python canvas tkinter
我想显示一个图像并在它上面绘制一个坐标系(x 轴,y 轴)。我可以显示图像
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)
Run Code Online (Sandbox Code Playgroud)
我也可以为 x 轴 / y 轴画一条线(如果你知道一种绘制闪光而不是线的方法会更好)
canvas = Canvas(root)
canvas.create_line(x0,y0,x1,y1)
canvas.pack()
Run Code Online (Sandbox Code Playgroud)
我不能做的是将这条线放在图像的顶部。我尝试使用 canvas.place(),但是当我把它放在图像的顶部时,我再也看不到图像了。有没有办法使画布透明?或者我还能做什么?我是 Tkinter 的新手。
谢谢。
编辑:显然不可能在 tkinter python 中制作透明画布透明画布
但是我可以在画布中添加背景图像然后绘制线条,以便我可以看到两者吗?
你必须把图像放在画布上,然后把轴线放在它上面:
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()
Run Code Online (Sandbox Code Playgroud)
达达!
| 归档时间: |
|
| 查看次数: |
2791 次 |
| 最近记录: |