Why is my Tkintering so bad?

dsavitsk dsavitsk at e-coli.net
Sat Jun 3 00:24:23 EDT 2000


example 1 does not work, example 2 does. anybody know why?
more importantly, i need to read text from a ScrolledText (Pmw) and i can't
do it.  The code i am attempting to use (or at least the relevant part) is
in Example 3.  i am used to things like...
x = Form.Text1.text (vb) so this is really foreign. essentially there is a
text box and a button. at startup the text box reads from a text file (this
works fine), then when the user pushes the button the contents of the text
box are written to the output window.  It is this step of connecting code to
events to visuals that i am not getting. any suggestions at all will be a
big help and greatly appreciated.

thanks,
doug

# Example 1 -------------------------------------
from Tkinter import *
root = Tk()
def buttonAction():
    print "click"

cmd = Button(root, text="Press").pack(side=TOP)
cmd.bind('<Button-1>', buttonAction)
root.mainloop()

# Example 2 --------------------------------------
from Tkinter import *
root = Tk()
def buttonAction():
    print "click"

cmd = Button(root, text="Press", command=buttonAction).pack(side=TOP)
root.mainloop()

# Example 3 ---------------------------------------
from Tkinter import *
import Pmw

def SaveEdits():
    x = st.get()
    print x

def MakeInterface():
    flt = Frame(root)
    st = Pmw.ScrolledText(flt, labelpos=N, label_text='Stuff',
text_wrap='none')
    st.importfile('TestData.txt')
    st.pack(fill=BOTH, expand=1, padx=5, pady=5)

    flt.pack(side=TOP, expand=YES, fill=X)

    flb = Frame(fl)
    cmdSave = Button(flb, width=20, text='Save Edits', borderwidth=3,
relief=GROOVE, command=SaveEdits).pack(side=TOP, pady=5)
    flb.pack(side=TOP, expand=YES, fill=X)

root = Tk()
root.title('window title')
MakeInterface()
root.mainloop()





More information about the Python-list mailing list