在ipython笔记本中集成tkinter事件循环

问题描述 投票:0回答:1

使用一个简单的tkinter gui像这样:

import tkinter as tk       

class Application(tk.Frame):              
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)   
        self.grid()                       
        self.createWidgets()

    def printHello(self):
        print("Hello")

    def createWidgets(self):
        self.quitButton = tk.Button(self, text='Quit',
            command=self.quit)            
        self.quitButton.grid(row=1,column=0)    
        self.printButton = tk.Button(self, text='Print',command=lambda: self.printHello())         
        self.printButton.grid(row=1,column=1) 
app = Application()                        
app.master.title('Sample application')     
app.mainloop()

我正在尝试遵循本文档,以将事件循环与ipython笔记本的内核连接:https://ipython.org/ipython-doc/3/config/eventloops.html

但是我似乎不太了解它是如何工作的:@register_integration('tk')

我如何准确地连接事件循环?如果可以,如何处理连接的事件循环?

python tkinter jupyter-notebook ipython event-loop
1个回答
0
投票
import tkinter as tk # Use your Tkinter widget as usual class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) ... # Here copy the skeleton from your given link ... @register_integration('tk') def loop_tk(kernel): ... class Timer(object): def __init__(self, func): self.app = Tk() # self.app.withdraw() self.func = func # Last statement in __init__ app = Application(self.app) app.master.title('Sample application') ... if __name__ == "__main__": # Where does 'kernel' come from? # loop_tk(kernel) pass
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.