怎么看python程序卡在哪里_Python程序卡住了
我是
Python新手,我正在編寫一個程序只是為了好玩.我的程序包含三個.py文件(假設是a.py,b.py,c.py). a將調用b或c中的函數,具體取決于用戶的選項.完成第一輪后,它會詢問用戶是想繼續還是只是退出程序.如果他們選擇繼續,它會再次詢問是否應該運行b或c.
我遇到的問題是,第一次,一個將調用函數完全正常,它運行平穩,然后當我選擇繼續它再次調用任何函數完全正常,它將進入函數,但然后該功能在第一步中陷入困境.
該程序沒有終止,沒有給出錯誤.它接受raw_input變量,但不會繼續.我想知道是否有某種方法迫使它接受變量,然后繼續這個過程(讓它“解開”).我已經嘗試過傳遞下一行了.那沒用.
以下是從請求繼續開始所需的步驟:
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('', 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 = ''
最佳答案 您需要重新構建代碼以僅創建一次根窗口,并且只調用一次mainloop. Tkinter的設計不能在單個進程中多次創建和銷毀root.
如果需要多個窗口,請使用Toplevel命令創建其他窗口.
總結
以上是生活随笔為你收集整理的怎么看python程序卡在哪里_Python程序卡住了的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ni软件可以卸载吗_最强大的电脑端卸载软
- 下一篇: qfii是什么意思(rqfii与qfii