Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 GUI-打印到文本框中,而不是Shell Py 3.3_Python_User Interface_Python 3.x_Tkinter_Tk - Fatal编程技术网

Python GUI-打印到文本框中,而不是Shell Py 3.3

Python GUI-打印到文本框中,而不是Shell Py 3.3,python,user-interface,python-3.x,tkinter,tk,Python,User Interface,Python 3.x,Tkinter,Tk,我正在创建一个Python factorial程序,我已经用tkinter将您输入到输入框中的数字打印到pythonshell中,但是如何将其打印到单独的文本框中呢?这是我的代码:从tkinter导入* def factorial(n): first = True for number in range(1, n+1): if first: answer = number first = False

我正在创建一个Python factorial程序,我已经用tkinter将您输入到输入框中的数字打印到pythonshell中,但是如何将其打印到单独的文本框中呢?这是我的代码:从tkinter导入*

def factorial(n):
    first = True
    for number in range(1, n+1):
        if first:
            answer = number
            first = False
        else:
            answer = answer * number
    return answer

    def callback():
    n = int(e.get())
    print(factorial(n))

    window = Tk()

    e = Entry(window)
    e.pack()

    t = Text()
    t.pack()

    e.focus_set()
    b = Button(window, text="get", width=10, command=callback)
    b.pack()

    mainloop()
您可以使用文本小部件的插入方法:

def callback():
    n = int(e.get())
    result = factorial(n)
    t.insert("1.0", str(result))