在GUI界面Tkinter Python中打印输出

在GUI界面Tkinter Python中打印输出,python,user-interface,tkinter,Python,User Interface,Tkinter,输出来自我运行代码的终端 我需要GUI界面中的输出。我想你没有什么东西可以放你的“嘿,whatsup,兄弟,我正在做一些非常有趣的事情。”。在tkinter中,您需要标签之类的东西来输出文本,或者如果有人点击按钮,您可以创建一个新的def并在那里定义该按钮必须执行的操作。使用仅打印打印到终端或fp。您可以创建一个新标签以“打印”到GUI from Tkinter import * def printSomething(): print "Hey whatsup bro, i am do

输出来自我运行代码的终端
我需要GUI界面中的输出。

我想你没有什么东西可以放你的
“嘿,whatsup,兄弟,我正在做一些非常有趣的事情。”
。在tkinter中,您需要标签之类的东西来输出文本,或者如果有人点击按钮,您可以创建一个新的def并在那里定义该按钮必须执行的操作。

使用仅打印打印到终端或fp。您可以创建一个新标签以“打印”到GUI

from Tkinter import *

def printSomething():
    print "Hey whatsup bro, i am doing something very interresting."

root = Tk()

button = Button(root, text="Print Me", command=printSomething)
button.pack()

root.mainloop()
您的评论示例

from Tkinter import *

def printSomething():
    # if you want the button to disappear:
    # button.destroy() or button.pack_forget()
    label = Label(root, text= "Hey whatsup bro, i am doing something very interresting.")
    #this creates a new label to the GUI
    label.pack() 

root = Tk()

button = Button(root, text="Print Me", command=printSomething) 
button.pack()

root.mainloop()

举个例子,如果我对范围(0,9)内的x执行:
:打印x
,我希望在GUI中打印x的值,该怎么办?我该怎么做?有代码的例子吗?hello@abccd bro,举个例子,如果我这样做:对于范围(0,9)中的x:打印x,我想在GUI中打印x的值?我该怎么做呢?嗯。。你可以查看我的新编辑@AnandVyas。如果我没有弄错的话,这将创建一行从0到8的标签。(我现在无法尝试)谢谢兄弟,它成功了!但是打印流程很糟糕,如果我一行打印200个数字,整个桌面都会填满。我该怎么做呢?一个简单的方法是创建一个框架的标签,设置窗口大小并创建一个滚动条。但这是一个不同的问题,你可以问或者找到一个已经被问过的问题
from Tkinter import *

def printSomething():
    # if you want the button to disappear:
    # button.destroy() or button.pack_forget()
    for x in range(9): # 0 is unnecessary
        label = Label(root, text= str(x))
    # this creates x as a new label to the GUI
        label.pack() 

root = Tk()

button = Button(root, text="Print Me", command=printSomething) 
button.pack()

root.mainloop()