[Tutor] Filtering text files
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Apr 15 03:34:14 EDT 2004
HI,
Can you choose a new subject for messages about a new
subject please? It gets very confusing to find a
completely different topic inside a message from
another thread, not to mention hard to find it in
the future from the archives. Thanks.
> C=Tkinter.Radiobutton(text="Change dir to C:", value=0).pack()
> D=Tkinter.Radiobutton(text="Change dir to D:", value=0).pack()
> E=Tkinter.Radiobutton(text="Change dir to E:", value=0).pack()
> F=Tkinter.Radiobutton(text="Change dir to F:", value=0).pack()
> G=Tkinter.Radiobutton(text="Change dir to G:", value=0).pack()
First problem is pack returns zero so all your variables store
zero not the widgets! You must do it in 2 stages:
C=Tkinter.Radiobutton(text="Change dir to C:", value=0)
C.pack()
> if C.select():
> C=Tkinter.Radiobutton(text="Change dir to C:",
> value=1,command=os.chdir('C:\\').pack()
This creates a new button. You only want to change the value I think.
Something like
C['value'] = 1
should be all you need
Also the command will call the os.system finction which returns
zero and that will be stored, not much use. You need to pass a
function object as the value of command, and do it where you
define the object.
I'd try something like:
def cdToC(): os.chdir('C:/')
def cdToD(): os.chdir('D:/')
etc
C=Tkinter.Radiobutton(text="Go to C:", value=0, command=cdToC)
or use lambda expressions like so:
C=Tkinter.Radiobutton(text="Go to C:",
value=0, command=lambda : os.chdir('C:/'))
HTH
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list