python 2.7 - tkinter event binding to button -


from tkinter import *  master = tk()  def callback():    print "click!"  b = button(master, text="ok", command=callback) b.pack()  mainloop() 

right running in ipython prints "click!" console. if result of script or function appear in gui box, under button how can achieve this? size of box need allocated in advanced?

edit: function want call more complicated callback above. when run following code, instead of printing clusone.head() prints

<function centroid @ 0x2cf3410>  

to output box. able print lines of data resulting function rather pointer address.

master = tk()   # output box prints address (pointer) result of running function.  #i see output in box.  df=pd.read_csv('8162013.csv') df=df.set_index('date1')  # initialize centroid. cen1=df.mean() v=ny.random.randn()+10 cen2=df.mean()-v train=df[0:1615]   def centroid(train,cen1,cen2):    in range(0,3):      # sum of squares. results in series containing 'date' , 'num'      sorted1=((train-cen1)**2).sum(1)     sorted2=((train-cen2)**2).sum(1)      # makes list of cluster1 , cluster2      a=[train.ix[i] in train.index if sorted1[i]<sorted2[i]]      b=[train.ix[i] in train.index if sorted1[i]>=sorted2[i]]       # dataframe...     clusone=pd.dataframe(a,columns=['es','us','gc'])     clustwo=pd.dataframe(b,columns=['es','us','gc'])   # update centroid.     cen1=clusone.mean()     cen2=clustwo.mean()       print clusone.head()      print "i'm computing centroid."     def callback():    listbox.insert(end, centroid)    b = button(master, text="cluster", command=callback)   listbox = listbox(master)    b.pack()    listbox.pack()     mainloop() 

you can create tkinter list box , add text every time 1 presses button:

from tkinter import *  master = tk()  def callback():    listbox.insert(end, "click!")  b = button(master, text="ok", command=callback) listbox = listbox(master) b.pack() listbox.pack()  mainloop() 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -