(Newbie) Menu Not Functioning
Stephen Ferg
steve at ferg.org
Wed Sep 18 15:20:42 EDT 2002
I can't help with your code, but I'd like to suggest something
that may be helpful.
Go to http://home.att.net/~stephen_ferg/easygui/
and download easygui.
Then the following program would put up a
nice graphic listbox from which you could choose.
For my own testing, I made the run() procedure
just print the command, rather than run it. But if you
change the code in the run() procedure, it should
work just fine for you.
-- Steve Ferg (steve at ferg.org)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HERE'S THE CODE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import os
import sys
from easygui import *
menu = [
"1. Copy Python Files from Office Computer to Floppy",
"2. Copy Python Files from Home Computer to Floppy",
"3. Copy Python Files from Floppy to Office Computer",
"4. Copy Python Files from Floppy to Home Computer",
]
def run(command):
print "Running", command # demo code
# os.system(command) # the real code
def officetoflop():
run("xcopy C:\MyDocu~1\*.py a:")
def hometoflop():
run("xcopy E:\MyDocu~1\*.py a:")
def floptooffice():
run("xcopy a:\*.py C:\MyDocu~1")
def floptohome():
run("xcopy a:\*.py E:\MyDocu~1")
while 1: # do forever
# use the easygui choicebox to make the selection
choice = choicebox("Choose your selection", "Copy Utilities", menu)
if choice == None:
print "Goodbye"
sys.exit(0)
menu_choice = choice[0] # get the first character of the choice
if menu_choice == "1":
officetoflop()
elif menu_choice == "2":
hometoflop()
elif menu_choice == "3":
floptooffice()
elif menu_choice == "4":
floptohome()
else:
print "Program Logic error. Choice:", choice
sys.exit(0)
More information about the Python-list
mailing list