【发布时间】:2019-09-05 05:20:35
【问题描述】:
这是帮助我在 python 上绘图的线。
packing_options[best_index].plot_sheets()
这就是它在 python 上的样子。这是图表的图片。 https://imgur.com/a/fRczosW
现在,我正在尝试 tkinter。我希望图表弹出。我怎样才能做到这一点 ?
window = tk.Tk()
packing_options[best_index].plot_sheets()
window.mainloop()
我试过这个。但是没用。
编辑: 因此,“matplotlib 将按照某人的评论使用。 这是代码:
def plot_sheet(self):
fig,ax = plt.subplots(1)
ax.set_xlim([0, self.W])
ax.set_ylim([0, self.L])
recs = []
for i in range(len(self.rect_list)):
if self.rect_rotate[i]:
ax.add_patch(patches.Rectangle((self.rect_pos[i][0], self.rect_pos[i][1]), self.rect_list[i].l, self.rect_list[i].w,linewidth=3,edgecolor='r'))
else:
ax.add_patch(patches.Rectangle((self.rect_pos[i][0], self.rect_pos[i][1]), self.rect_list[i].w, self.rect_list[i].l,linewidth=3,edgecolor='r'))
plt.show()
def plot_sheets(self):
for i in range(len(self.sheets)):
self.sheets[i].plot_sheet()
这是绘图的代码。 pack_options[best_index] 也是这里的一个函数。它绘制了大约 10-20 个图,因为有一个循环。 如何在这里应用 matplotlib 后端?
【问题讨论】:
-
您想在新窗口中显示您的图像吗?如果是这样,请查看TopLevel widget
-
不是图片,而是图表。
-
对于图形,您需要使用 matplotlib 后端进行 tkinter。可以在here 找到一个示例。将您的画布放在 TopLevel 窗口上并在那里绘制图表。
-
这个弹出窗口还有其他方法吗?
-
不,在 tkinter 中没有其他方法可以弹出窗口。实现上述方法非常简单。
标签: python python-3.x tkinter tkinter-canvas