Tkinter-Python从类中调用第二个窗口

时间:2020-06-26 22:01:35

标签: python-3.x tkinter canvas frontend

我正在尝试从外部函数调用第二个窗口,但我不知道缺少什么。通过使用-command = ventana_proceso()-,类“ TestFrame()”中的'submit_btn'中的事件将调用事件'ventana_proceso()',但实际上,这会使按钮隐藏,并且如果您调用另一个函数,即command = send_data()该按钮再次可见。是否知道我在做什么错以及为什么第二个窗口未运行?非常感谢!

import tkinter as tk
from tkinter import *
from tkinter import ttk

from PIL import ImageTk, Image
from tkinter import Label


def send_data(salario=int, correo=str, domicilio=str, alterno=str, edad=int, descripcion=str):
    '''

    salario_info = salario.get()
    titulo_info = titulo.get()
    jornada_info = jornada.get()
    correo_info = correo.get()
    domicilio_info = domicilio.get()
    contacto_alterno_info = alterno.get()
    edad_info = str(edad.get())
    descripcion_info = descripcion.get()
    print(salario_info, "\t", titulo_info, "\t", jornada_info, "\t", correo_info, "\t", domicilio_info, "\t",
    contacto_alterno_info, "\t", edad_info, "\t", descripcion_info, "\t")
    '''


pass


def ventana_proceso():
    # I don't know if here there is missing something for invoking the button 'submit_btn' in class TestFrame() down there
    win = tk.Toplevel()
    win.geometry('500x500')
    validar_button = tk.Label(win,
                               text='Validando...',
                               command=lambda: [funcA(), funcB(), funcC()])
    validar_button.pack()

    labelA = tk.Label(win, text="A")
    labelB = tk.Label(win, text="B")
    labelC = tk.Label(win, text="C")

    labelA.pack()
    labelB.pack()
    labelC.pack()

    win.mainloop()

    def funcA():
        labelA["text"] = "Funcion 1 "
        progressbar = ttk.Progressbar()
        progressbar.place(x=30, y=60, width=200)

    def funcB():
        labelB["text"] = "Funcion 2"

    def funcC():
        labelC["text"] = "Funcion 3"



# Test frame class. The same frame is used to create 4 instances.
class TestFrame(tk.Frame):
    def __init__(self, master=None, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        super().__init__(master)



        # Test Entry fields --------------------------------------------------------------------------------------------
        titulo_empleo               = tk.Label(master, text="Título del Empleo:").grid(row=0, column=0)
        titulo_empleo_entry         = tk.Entry(master, bd=5).grid(row=0, column=1)
        salario                = tk.Label(master, text="Salario:").grid(row=0, column=2)
        salario_entry          = tk.Entry(master, bd=5).grid(row=0, column=3)

        nombre_ofertante = tk.Label(master, text="Nombre del ofertante:").grid(row=1, column=0)
        nombre_ofertante_entry = tk.Entry(master, bd=5).grid(row=1, column=1)
        telefono = tk.Label(master, text="Teléfono:").grid(row=1, column=2)
        telefono_entry = tk.Entry(master, bd=5).grid(row=1, column=3)

        descripcion = tk.Label(master, text="Descripción de la vacante:").grid(row=2, column=0)
        descripcion_entry = tk.Entry(master, bd=5).grid(row=2, column=1)
        direccion = tk.Label(master, text="Dirección de la empresa:").grid(row=2, column=2)
        direccion_entry = tk.Entry(master, bd=5).grid(row=2, column=3)

        email = tk.Label(master, text="Email del anunciante:").grid(row=3, column=0)
        email_entry = tk.Entry(master, bd=5).grid(row=3, column=1)
        ciudad = tk.Label(master, text="Cuidad:").grid(row=3, column=2)
        ciudad_entry = tk.Entry(master, bd=5).grid(row=3, column=3)





        # Test dropdowns------------------------------------------------------------------------------------------------
        logo         = tk.Label(master, text="Jornada Laboral:").grid(row=14, column=0)
        list_of_options             = ['->',"1/2 Lunes a Viernes", "Completo de Lunes a Viernes", "Sábados y Domingos", "Abierto"]
        first_option                = tk.StringVar(master)
        first_option.set(list_of_options[0])
        logo_label         = tk.OptionMenu(master, first_option, *list_of_options).grid(row=14, column=1)

        educacion = tk.Label(master, text="Escolaridad:").grid(row=14, column=2)
        list_of_options             = ["->", "Nivel Básico", "Preparatoria", "Lic / Ing", "Maestría/Doctorado", "No Dice"]
        first_option                = tk.StringVar(master)
        first_option.set(list_of_options[0])
        educacion_label         = tk.OptionMenu(master, first_option, *list_of_options).grid(row=14, column=3)

        edad = tk.Label(master, text="Rango de edad:").grid(row=15, column=0)
        list_of_options = ['->', "16-18", "18-40", "Pensionados", "No importa"]
        first_option = tk.StringVar(master)
        first_option.set(list_of_options[0])
        edad_label = tk.OptionMenu(master, first_option, *list_of_options).grid(row=15, column=1)

        genero = tk.Label(master, text="Género:").grid(row=15, column=2)
        list_of_options = ["->", "Solo mujeres", "Solo hombres", "Ambos", "No Dice"]
        first_option = tk.StringVar(master)
        first_option.set(list_of_options[0])
        genero_label = tk.OptionMenu(master, first_option, *list_of_options).grid(row=15, column=3)

        segmento = tk.Label(master, text="Área laboral:").grid(row=16, column=0)
        list_of_options = ['->', "Administrativo", "Compras", "Analista", 'Arte/Creativo', 'Auditor', 'Ciencias',
                           'Consultoría',  'Diseño', 'Educación', 'Distribución', 'Producción', 'Ventas', 'Finanzas',
                            'Ingeniería', 'Investigación', 'Legal', 'Marketing', 'Publicidad', 'Recursos humanos',
                            'Redacción / Edición', 'Relaciones públicas', 'Calidad',
                           'Atención al cliente', 'Tecnologías de la información','Otro']
        first_option = tk.StringVar(master)
        first_option.set(list_of_options[0])
        segmento_label = tk.OptionMenu(master, first_option, *list_of_options).grid(row=16, column=1)

        experiencia = tk.Label(master, text="Experiencia:").grid(row=16, column=2)
        list_of_options = ["->", "Min 2 años", "Min 5 años", "Sin experiencia", "No Dice"]
        first_option = tk.StringVar(master)
        first_option.set(list_of_options[0])
        experiencia_label = tk.OptionMenu(master, first_option, *list_of_options).grid(row=16, column=3)



        # Test checkbox fields -----------------------------------------------------------------------------------------
        logotipo = tk.Label(master, text="El ofertante tiene logo:").grid(row=20, column=0)
        logotipo_entry = tk.Checkbutton(master, bd=5).grid(row=20, column=1)
        redes_sociales = tk.Label(master, text="El empleo se publicó en redes sociales:").grid(row=20, column=2)
        redes_sociales_entry = tk.Checkbutton(master, bd=5).grid(row=20, column=3)
        comentarios = tk.Label(master, text="Tiene comentarios negativos:").grid(row=21, column=0)
        comentarios_entry = tk.Checkbutton(master, bd=5).grid(row=21, column=1)



        # Send button--------------------------------------------------------------------------------------------------
        submit_btn = tk.Button(text="Enviar", width="15", height="1",
                               command=ventana_proceso(), background="PeachPuff3")
        submit_btn.place(relx=0.87, rely=0.92, anchor=CENTER)


        pass
    pass


class TestMainApplication(tk.Frame):

    def __init__(self, master, *args, **kwargs):
        tk.Frame.__init__(self, master, *args, **kwargs)
        super().__init__(master)

        title                       = "Validador de Empleo"
        self.grid()

        # Assign the weight to each row and column as 1. This is required to align the parameters in grid.
        for r in range(3):
            self.master.rowconfigure(r, weight=1)
        for c in range(8):
            self.master.columnconfigure(c, weight=1)

        self.master.title(title)

        # Add two instances of the class TestFrame
        self.testFrame1            = TestFrame(master)
        self.testFrame2            = TestFrame(master)
        self.testFrame3            = TestFrame(master)
        self.testFrame4            = TestFrame(master)

        self.testFrame1.grid(row=0, column=0, rowspan=3, columnspan=3, sticky=tk.W+tk.E+tk.N+tk.S)
        self.testFrame2.grid(row=3, column=0, rowspan=3, columnspan=3, sticky=tk.W+tk.E+tk.N+tk.S)
        self.testFrame3.grid(row=0, column=3, rowspan=2, columnspan=3, sticky=tk.W+tk.E+tk.N+tk.S)
        self.testFrame3.grid(row=2, column=3, rowspan=4, columnspan=3, sticky=tk.W+tk.E+tk.N+tk.S)

        pass
    pass


# Main application is created here.
root                   = tk.Tk()
mainApplication        = TestMainApplication(root)
root.mainloop()







 

0 个答案:

没有答案