Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter或try/except问题-代码在弹出后停止执行_Python_Tkinter_Try Except - Fatal编程技术网

Python Tkinter或try/except问题-代码在弹出后停止执行

Python Tkinter或try/except问题-代码在弹出后停止执行,python,tkinter,try-except,Python,Tkinter,Try Except,我的问题是: 有一个公司地址数据库-如果您试图创建发票,但发票地址丢失,则会创建一个弹出提示,提示您输入地址。但是,一旦完成,代码的其余部分就永远不会执行。不确定是否与新窗口或try/except语句有关 def addPopUp(table): def popClose(): print("closing") popup2.destroy() def addAddress(table, address): file = open

我的问题是: 有一个公司地址数据库-如果您试图创建发票,但发票地址丢失,则会创建一个弹出提示,提示您输入地址。但是,一旦完成,代码的其余部分就永远不会执行。不确定是否与新窗口或try/except语句有关

def addPopUp(table):
    def popClose():
        print("closing")
        popup2.destroy()

    def addAddress(table, address):
        file = open('addresses.csv', 'a')
        file.write("\n{},{}".format(table[3], address))
        file.close()
        popup2.destroy()


    popup2 = Tk()
    popup2.wm_title("Add address")
    label = Label(popup2, text="Address needed for {}".format(table[3]))
    label.grid(row=0, column=0, columnspan=3)
    newAdd = Entry(popup2)
    newAdd.grid(row=1, column=0, columnspan=3,)
    addBut = Button(popup2, text="Add", command= lambda:addAddress(table,newAdd.get()))
    addBut.grid(row=2,column=0)
    cancel = Button(popup2, text="Cancel",command = popClose)
    cancel.grid(row=2, column=2)

    popup2.mainloop()

def generateInvoice():

        print("Generating invoice")

        sel = invoices.selection()
        if  sel == ():
            print("You need to select a line")
            return
        line = int(sel[0][1::])-1

        global addresses
        if True:
            try:
                addresses[invoiceData[line][3]] == None

            except:
                addPopUp(invoiceData[line])
        # THIS CODE NEVER HAPPENS IF THERE'S AN EXCEPTION vvvvvvvv
                addresses = loadAddresses()



        def addPO():
            newPO = poNum.get()
            if newPO != "":
                print(invoiceData[line])
                invoiceData[line].pop(7)
                invoiceData[line].insert(7,newPO)
                print(invoiceData[line])



            popup.destroy()
            createPdf(invoiceData[line],addresses)
        def notNeeded():

            popup.destroy()
            createPdf(invoiceData[line],addresses)

        def popClose():
            print("closing")
            popup.destroy
        if invoiceData[line][7]=='':
            popup = Tk()
            popup.wm_title("PO needed?")
            label = Label(popup,text = "Add PO")
            label.grid(row=0,column=0,columnspan = 3)
            poNum = Entry(popup)
            poNum.grid(row=1,column=0,columnspan = 3)
            addBut = Button(popup, text = "Add", command=addPO)
            noNeed = Button(popup,text = "Not needed", comman=notNeeded)
            addBut.grid(row=2,column=0)
            noNeed.grid(row=2,column=1)
            cancel = Button(popup,text = "Cancel", command=popClose)
            cancel.grid(row=2,column=2)

            popup.mainloop()
        else:
            createPdf(invoiceData[line],addresses)

你还没有提供一个。无论如何,在使用
tkinter
时,不应多次调用
Tk()。如果您想要多个窗口,请致电创建它们。谢谢。我试试看。注意
Tk()
至少需要调用一次。此实例通常命名为
root
,表示主应用程序的窗口。@AndrewZmurowski:请阅读并感谢所有帮助,尽管我没有提供有效的示例。结果表明,该代码与popup2.quit()一起工作