Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从Jupyter笔记本中的Tkinter文本小部件获取文本?_Python_Python 3.x_Tkinter_Jupyter Notebook_Jupyter - Fatal编程技术网

Python 如何从Jupyter笔记本中的Tkinter文本小部件获取文本?

Python 如何从Jupyter笔记本中的Tkinter文本小部件获取文本?,python,python-3.x,tkinter,jupyter-notebook,jupyter,Python,Python 3.x,Tkinter,Jupyter Notebook,Jupyter,我在Jupyter中使用tkinter编写了一个简单的GUI代码: 如何获取用户输入的文本? 如果我将text.get'1.0',end'添加到代码的末尾,它将不起作用,同样,当我将text.get'1.0',end'添加到另一个单元格时,它不会开始执行,直到我关闭根窗口,然后它会给出一个错误。 像这样: In[1]: from tkinter import * root = Tk() text = Text(root, width = 40, height = 15

我在Jupyter中使用tkinter编写了一个简单的GUI代码:

如何获取用户输入的文本? 如果我将text.get'1.0',end'添加到代码的末尾,它将不起作用,同样,当我将text.get'1.0',end'添加到另一个单元格时,它不会开始执行,直到我关闭根窗口,然后它会给出一个错误。 像这样:

In[1]: from tkinter import *
       root = Tk()
       text = Text(root, width = 40, height = 15)
       text.pack()
       root.mainloop()
import tkinter as tk
root = tk.Tk()
text = tk.Text(root, width=40, height = 15)
text.pack()
tk.Button(root, text='get text', command=lambda: print(text.get('1.0', tk.END))).pack()
root.mainloop()
在[2]中,在我关闭Tk窗口之前不会开始执行,在[2]中关闭窗口并开始运行后,会出现以下错误:

TclError: invalid command name ".!text"

无法从ipython interactive与tkinter Main循环交互。 如果添加“获取文本”按钮,按下该按钮将检索文本小部件内容:

像这样:

In[1]: from tkinter import *
       root = Tk()
       text = Text(root, width = 40, height = 15)
       text.pack()
       root.mainloop()
import tkinter as tk
root = tk.Tk()
text = tk.Text(root, width=40, height = 15)
text.pack()
tk.Button(root, text='get text', command=lambda: print(text.get('1.0', tk.END))).pack()
root.mainloop()

无法从ipython interactive与tkinter Main循环交互。 如果添加“获取文本”按钮,按下该按钮将检索文本小部件内容:

像这样:

In[1]: from tkinter import *
       root = Tk()
       text = Text(root, width = 40, height = 15)
       text.pack()
       root.mainloop()
import tkinter as tk
root = tk.Tk()
text = tk.Text(root, width=40, height = 15)
text.pack()
tk.Button(root, text='get text', command=lambda: print(text.get('1.0', tk.END))).pack()
root.mainloop()