我试图创建一个脚本,在python GUI中绘制图像上的线条。我已经能够在GUI上获取图像,但不知道如何绘制其他行。脚本应该能够循环,这样我就可以绘制更多的行。
到目前为止我所拥有的:
import tkinter as Tk
root = Tk.Tk()
background_image=Tk.PhotoImage(file="map.png")
background_label = Tk.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root.wm_geometry("794x370")
root.title('Map')
root.mainloop()
答案 0 :(得分:4)
首先将图像放在画布上,可以做到这一点:
import tkinter as Tk
root = Tk.Tk()
canvas = Tk.Canvas(root)
background_image=Tk.PhotoImage(file="map.png")
canvas.pack(fill=Tk.BOTH, expand=1) # Stretch canvas to root window size.
image = canvas.create_image(0, 0, anchor=Tk.NW, image=background_image)
line = canvas.create_line(10, 10, 100, 35, fill="red")
root.wm_geometry("794x370")
root.title('Map')
root.mainloop()