我正在学习Tkinter
,我需要一个Button,然后当我点击它时,用一些代码做一些事情,然后打印结果。我怎样才能让我的GUI输出结果?
我开始用这样的:
from Tkinter import *
import heapq
root = Tk()
root.title("TEST")
root.geometry("800x600")
#-------------------CODE-----------------------
def makeHuffTree(symbolTupleList):
trees = list(symbolTupleList)
heapq.heapify(trees)
while len(trees) > 1:
childR, childL = heapq.heappop(trees), heapq.heappop(trees)
parent = (childL[0] + childR[0], childL, childR)
heapq.heappush(trees, parent)
return trees[0]
def printHuffTree(huffTree, prefix = ''):
if len(huffTree) == 2:
print huffTree[1], prefix
else:
printHuffTree(huffTree[1], prefix + '0')
printHuffTree(huffTree[2], prefix + '1')
def OnButton():
exampleData = [(0.124167 , 'e'), (0.0969225 , 't'),(0.0820011 , 'a'),]
huffTree = makeHuffTree(exampleData)
printHuffTree(huffTree)
button = Button(root, text="Press me!", command=OnButton)
button.pack()
root.mainloop()
如何我现在做一个我的GUI输出的结果?
你在哪里创建按钮? – 2010-12-13 11:53:36
该按钮不是问题,我可以创建它,但然后我不能连接这个按钮来运行代码,之后我按下它,然后导致GUI。 – thaking 2010-12-13 12:07:37
@thaking嗨我一个使用tkinter创建程序deflate算法?你的huffman树的代码wud b对我有帮助..你的plz通过我吗?任何形式的帮助赞赏 – MalTec 2012-01-30 12:55:25