在GUI界面Tkinter Python中打印输出

时间:2017-03-16 08:06:53

标签: python user-interface tkinter

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()

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

2 个答案:

答案 0 :(得分:2)

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

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()

您的评论示例

nssm get MyWindowsService AppParameters > tempFile
for /f "delims=" %%a in ('
    ^< tempFile find /v ""
') do (
    nssm.exe set MyWindowsService AppParameters "%%a --baseUrl helloworld.txt"
)

答案 1 :(得分:0)

我认为你没有把你的"Hey whatsup bro, i am doing something very interresting."放进去。在tkinter中,你需要像Label这样的东西来放置文本,或者你创建一个新的def并定义按钮必须做什么,如果有人点击在它上面。