Python 在Jupyter笔记本电脑中以内联方式显示TkInter输出

Python 在Jupyter笔记本电脑中以内联方式显示TkInter输出,python,tkinter,ipython,jupyter,Python,Tkinter,Ipython,Jupyter,我正在尝试使用TkInter库在Python中创建一个简单的实时绘图应用程序,我需要它将内联显示为Jupyter笔记本的输出,而不是显示在新窗口中。 到目前为止,我的测试应用程序正是我需要它做的,但tkinter在Jupyter IPython中运行时会打开一个新窗口: from tkinter import * import time root = Tk() root.title = "Laser Drawing" root.resizable(0,0) root.wm_attribut

我正在尝试使用TkInter库在Python中创建一个简单的实时绘图应用程序,我需要它将内联显示为Jupyter笔记本的输出,而不是显示在新窗口中。 到目前为止,我的测试应用程序正是我需要它做的,但tkinter在Jupyter IPython中运行时会打开一个新窗口:

 from tkinter import *
 import time

root = Tk()
root.title = "Laser Drawing"
root.resizable(0,0)
root.wm_attributes("-topmost", 1)
centerX = 100
centerY = 100
radius = 2
resolution = [1280, 720]

canvas = Canvas(root, width=resolution[0], height=resolution[1], bd=0, highlightthickness=0)
canvas.pack()

def drawCircle():
    circle = canvas.create_oval(centerX-radius, centerY+radius, centerX+radius, centerY-radius, fill="red", outline="red")

for i in range (0, 1000):
    drawCircle()
    root.update()
    time.sleep(0.01)
    centerX+=1
    centerY+=1
有没有办法使tkinter生成的输出以内联方式显示,而无需打开新窗口?
或者,我可以考虑使用哪些库来创建类似的交互式绘图程序来显示联机?我尝试过使用Jupyter的javascript/HTML magics,它确实可以内联显示画布,但我希望能够在Python中实现这一点。

您能添加您正在使用的代码吗?@RickM。对不起,我无意中提交了之前包含的代码。代码现在就在那里。
jsfiddle
是一个很好的替代方法,这里还有另一个解决方法: