我刚开始学习Python,正在写一个有趣的程序。我的程序包含三个.py文件(假设为a.py、b.py、c.py)。a将根据用户的选择调用b或c中的函数。第一轮完成后,它会询问用户是要继续还是退出程序。如果他们选择继续,它会再次询问是否运行b或c。
我遇到的问题是,在第一次执行时,a会完美地调用b或c中的函数,它运行得很顺利,然后当我选择继续时,它再次完美地调用两个函数中的任意一个,它会进入函数,但是函数会在第一步卡住。
程序没有终止,也没有报错。它接受了输入变量,但不会继续执行。我想知道是否有某种方法来强制它接受变量,然后继续处理(使其'解锁')。我已经尝试在下一行上放置'pass',但没有效果。
以下是从请求继续开始执行的步骤:
我遇到的问题是,在第一次执行时,a会完美地调用b或c中的函数,它运行得很顺利,然后当我选择继续时,它再次完美地调用两个函数中的任意一个,它会进入函数,但是函数会在第一步卡住。
程序没有终止,也没有报错。它接受了输入变量,但不会继续执行。我想知道是否有某种方法来强制它接受变量,然后继续处理(使其'解锁')。我已经尝试在下一行上放置'pass',但没有效果。
以下是从请求继续开始执行的步骤:
Continue = tkMessageBox.askyesno('Cypher Program', 'I have completed the task'
+ '\nWould you like to do anything else?')
## This is in a.py;
if Continue == True:
cyp()
def cyp():
global root
root = Tk()
root.title("Cypher Program")
root['padx'] = 40
root['pady'] = 20
textFrame = Frame(root)
Label(root, text = 'What would you like to do?').pack(side = TOP)
widget1 = Button(root, text = 'Encrypt a file', command = encrypt)
widget1.pack(side = LEFT)
widget2 = Button(root, text = 'Decrypt a file', command = decrypt)
widget2.pack(side = RIGHT)
widget3 = Button(root, text = 'Quit', command = quitr)
widget3.pack(side = BOTTOM)
root.mainloop()
def encrypt():
root.destroy()
encrypt3.crypt()
##Then from there it goes to b.py;
def crypt():
entry('Enter a file to encrypt:', selectFile)
def entry(msg1, cmd):
global top
top = Toplevel() ##changed it to Toplevel
top.title("File Encrypion")
top['padx'] = 40
top['pady'] = 20
textFrame = Frame(top)
entryLabel = Label(textFrame)
entryLabel['text'] = msg1
entryLabel.pack(side = LEFT)
global entryWidget
entryWidget = Entry(textFrame)
entryWidget['width'] = 50
entryWidget.pack(side = LEFT)
textFrame.pack()
button = Button(top, text = "Submit", command = cmd)
button.pack()
button.bind('<Return>', cmd)
top.mainloop()
def selectFile():
if entryWidget.get().strip() == "":
tkMessageBox.showerror("File Encryption", "Enter a file!!")
else:
global enc
enc = entryWidget.get().strip() + '.txt'
top.destroy() ##gets stuck here
##This is the rest of crypt(). It never returns to the try statement
try:
view = open(enc)
except:
import sys
sys.exit(badfile())
text = ''