Ana*_*yas 4 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()
Run Code Online (Sandbox Code Playgroud)
输出来自我运行代码的终端,我需要 GUI 界面中的输出。
使用 print 仅打印到终端或 fp。您可以创建一个新标签以“打印”到 GUI。
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()
Run Code Online (Sandbox Code Playgroud)
您的评论示例
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()
Run Code Online (Sandbox Code Playgroud)