执行popup tkinter wind时出现的问题

2024-09-30 04:41:02 发布

您现在位置:Python中文网/ 问答频道 /正文

在这个应用程序中,我试图执行一个弹出窗口,用户可以在其中写入日期。这个弹出窗口必须发生在用户单击我已经创建的提交按钮之后。用户在弹出窗口中输入的日期必须保存到变量中,该变量将在以后的代码中使用。为了做到这一切,我尝试了以下方法:

def CreateOrderPop(self):
            def popup():
                #contenido = input("Contenido de Orden ")
                #diaDeEntregar = input("Dia de Entrega")
                self.userentryA = Entry("Dia de Entrega: ")
                self.userentryA.pack()
                self.userentryAbu = Button(text= "Guardar", command = self.guardarFechaOrden)
                self.userentryAbu.pack()
            def guardarFechaOrden(self):
                global userDate
                userDate = self.userentryA.get()
                self.destroy()    

    def submit(self):
        result = next(self.counter)
        global orderResult
        orderResult = str(result)
        global contents1
        contents1 = ("Nombre: {}".format(self.entry_name.get())) 
        global contents2
        contents2 = ("Email: {}".format(self.entry_email.get()))
        global contents3
        contents3 = ("Num Cel/Tel: {}".format(self.entry_numtc.get()))
        global contents4
        contents4 = ("Información Adicional: {}".format(self.entry_addinf.get(1.0, "end")))

        def CreateOrder():
            fecha = datetime.now()
            fechaDeCreacion = fecha.strftime(" %A, %B %d, %Y" )
            #diaDeEntregar = userDate
            #global fechaDeEntrega
            #fechaDeEntrega = fechaDeCreacion + str(diaDeEntregar)
            numOrden = orderResult
            return fechaDeCreacion,  orderResult


        completeOrden = [contents1, contents2,  contents3, contents4, CreateOrder()]
        completeOrdenEnum = "Orden Num:" + orderResult, completeOrden
        Database.mainDatabase.append(completeOrdenEnum)

        command = self.CreateOrderPop()

在运行代码并单击submit按钮之后,除了我没有得到我想要的弹出窗口之外,一切都正常运行。在

变化

我添加了这个类来帮助我创建我想要的:

^{pr2}$

以前的代码和此编辑的代码:

def submit(self):

        result = next(self.counter)
        print (result)
        def controLoo():
            if result == 1: 
                self.CreateOrderPop()
        command = controLoo()
        global orderResult
        orderResult = str(result)
        global contents1
        contents1 = ("Nombre: {}".format(self.entry_name.get())) 
        global contents2
        contents2 = ("Email: {}".format(self.entry_email.get()))
        global contents3
        contents3 = ("Num Cel/Tel: {}".format(self.entry_numtc.get()))
        global contents4
        contents4 = ("Información Adicional: {}".format(self.entry_addinf.get(1.0, "end")))

        def CreateOrder():
            fecha = datetime.now()
            fechaDeCreacion = fecha.strftime(" %A, %B %d, %Y" )
            #diaDeEntregar = PopOrden
            #global fechaDeEntrega
            #fechaDeEntrega = fechaDeCreacion + str(diaDeEntregar)
            numOrden = orderResult
            return fechaDeCreacion,  orderResult


        completeOrden = [contents1, contents2,  contents3, contents4, CreateOrder()]
        completeOrdenEnum = "Orden Num:" + orderResult, completeOrden
        Database.mainDatabase.append(completeOrdenEnum)


        command = self.database_window()


        self.clear()


        messagebox.showinfo(title = "Orden #"+ orderResult, message = "Orden Guardada")

但是,我现在有一个空白tk popu的问题,它也是由我想要的弹出窗口生成的。在


Tags: selfformatgetdefresultglobalentrycontents1
2条回答

为什么不直接用留言框呢

from tkinter import *
import tkMessageBox
root = Tk()

def popUp():
    result = tkinter.messageBox.popUp("Quiz","Are you ready? ")
    # result wil be yes or no
    if result == 'yes':  
        #do something
   else:
        # do something

submitButton = Button(root,text= "Submit")
submitButton.bind("<Button-1",popup) 
# onleft click on submit popup method gets called
submitButton.pack()

我不确定您所说的一切正常运行是什么意思,因为您的代码似乎有一些主要的格式问题(至少可以说是缩进)。然而,“弹出窗口”通常是通过Toplevel()小部件实现的。请参阅this有用资源。在我看来,这是一个很好的资源。在

另外,您可能会发现this问题的答案很有帮助。在

相关问题 更多 >

    热门问题