Juypter中的Tkinter PhotoImage

时间:2017-04-20 12:49:31

标签: python python-2.7 tkinter jupyter-notebook ipython-notebook

(相当新的python) 我的代码在Spyder(Python 2.7)(我编写它的地方)中运行时效果很好,但我想把它放在Juypter笔记本中(因为我还有其他工作可以放在它旁边),但它似乎无法找到'MaxShearStress .PNG”。

cookies

这是juypter中出现的错误:

import math
import numpy as np
import matplotlib.pyplot as plt
%gui tk
import Tkinter as tk


class App:

    def __init__(self, master):
        root.title("Max Shear Stress")
        frame = tk.Frame(master)
        frame.pack()

        self.button = tk.Button(
            frame, text="CONTINUE TO DATA INPUT", command=frame.quit
            )
        self.button.pack(side='left')

        self.s_block = tk.Button(frame, text="SHOW STRESS BLOCK DIAGRAM",     command=self.stress_b)
        self.s_block.pack(side='left')

    def stress_b(self):
        #root.title("Max Shear Stress")
        img = tk.PhotoImage(file= "MaxShearStress.PNG")
        c = tk.Canvas(width = 600, height = 400)
        c.pack(side='top', fill='both', expand='yes')
        c.create_image(10, 10, image=img, anchor='nw')
        root.mainloop()

root = tk.Tk()

app = App(root)

root.mainloop()
root.destroy()

但是我把它保存在与Python编码相同的文件夹中?

0 个答案:

没有答案