0

I have a project in Pyhton with some windows/form on Win11, but when I try to link a window with another one, they overlap. I want to show a window one at a time, but I don't see anything in the code to achieve this behaviour.

The forms were created with VB6 and then transformed into python code through TKinter Designer complement.

I have tried to close the parent window afte the call of the child one but with no results

Here is an example of the code:

Window 'Configuration':


    import os, sys
    if sys.version_info[0] == 2:
        from Tkinter import *
        from tkFont import Font
        from ttk import *
        #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
        from tkMessageBox import *
        #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
        #import tkFileDialog
        #import tkSimpleDialog
    else:  #Python 3.x
        from tkinter import *
        from tkinter.font import Font
        from tkinter.ttk import *
        from tkinter.messagebox import *
        #import tkinter.filedialog as tkFileDialog
        #import tkinter.simpledialog as tkSimpleDialog    #askstring()
    
    import ConfGeneral, ConfCorte, ConfMedidasCorte
    
    class Application_ui(Frame):
        #The class will create all widgets for UI.
        def __init__(self, master=None):
            Frame.__init__(self, master)
            self.master.title('Seleccione configuracion')
            self.master.geometry('470x363')
            self.createWidgets()
    
        def createWidgets(self):
            self.top = self.winfo_toplevel()
    
            self.style = Style()
    
            self.cmd_ConfGeneralVar = StringVar(value='General')
            self.style.configure('Tcmd_ConfGeneral.TButton', font=('MS Sans Serif',18,'bold'))
            self.cmd_ConfGeneral = Button(self.top, text='General', textvariable=self.cmd_ConfGeneralVar, command=self.cmd_ConfGeneral_Cmd, style='Tcmd_ConfGeneral.TButton')
            self.cmd_ConfGeneral.setText = lambda x: self.cmd_ConfGeneralVar.set(x)
            self.cmd_ConfGeneral.text = lambda : self.cmd_ConfGeneralVar.get()
            self.cmd_ConfGeneral.place(relx=0.085, rely=0.11, relwidth=0.309, relheight=0.311)
    
            self.cmd_ConfTiposCorteVar = StringVar(value='Tipos de Corte')
            self.style.configure('Tcmd_ConfTiposCorte.TButton', font=('MS Sans Serif',18,'bold'))
            self.cmd_ConfTiposCorte = Button(self.top, text='Tipos de Corte', textvariable=self.cmd_ConfTiposCorteVar, command=self.cmd_ConfTiposCorte_Cmd, style='Tcmd_ConfTiposCorte.TButton')
            self.cmd_ConfTiposCorte.setText = lambda x: self.cmd_ConfTiposCorteVar.set(x)
            self.cmd_ConfTiposCorte.text = lambda : self.cmd_ConfTiposCorteVar.get()
            self.cmd_ConfTiposCorte.place(relx=0.579, rely=0.11, relwidth=0.309, relheight=0.311)
    
            self.cmd_MedidasCorteVar = StringVar(value='Medidas de Corte')
            self.style.configure('Tcmd_MedidasCorte.TButton', font=('MS Sans Serif',18,'bold'))
            self.cmd_MedidasCorte = Button(self.top, text='Medidas de Corte', textvariable=self.cmd_MedidasCorteVar, command=self.cmd_MedidasCorte_Cmd, style='Tcmd_MedidasCorte.TButton')
            self.cmd_MedidasCorte.setText = lambda x: self.cmd_MedidasCorteVar.set(x)
            self.cmd_MedidasCorte.text = lambda : self.cmd_MedidasCorteVar.get()
            self.cmd_MedidasCorte.place(relx=0.323, rely=0.573, relwidth=0.309, relheight=0.311)
    
    
    class Application(Application_ui):
        #The class will implement callback function for events and your logical code.
        def __init__(self, master=None):
            Application_ui.__init__(self, master)
    
        def cmd_ConfGeneral_Cmd(self, event=None):
            ConfGeneral.Application()
    
        def cmd_ConfTiposCorte_Cmd(self, event=None):
            ConfCorte.Application()
    
        def cmd_MedidasCorte_Cmd(self, event=None):
            ConfMedidasCorte.Application()
    
    if __name__ == "__main__":
        top = Tk()
        Application(top).mainloop()

Window 'General Configuration'


    import os, sys

    myDir = os.getcwd()
    sys.path.append(myDir)
    
    from pathlib import Path
    path = Path(myDir)
    a=str(path.parent.absolute())
    
    sys.path.append(a)
    
    import src.Controlador.Transacciones as Transacciones
    import Configuraciones as Configuraciones
    
    if sys.version_info[0] == 2:
        from Tkinter import *
        from tkFont import Font
        from ttk import *
        #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
        from tkMessageBox import *
        #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
        #import tkFileDialog
        #import tkSimpleDialog
    else:  #Python 3.x
        from tkinter import *
        from tkinter.font import Font
        from tkinter.ttk import *
        from tkinter.messagebox import *
        #import tkinter.filedialog as tkFileDialog
        #import tkinter.simpledialog as tkSimpleDialog    #askstring()
    
    class Application_ui(Frame):
        #The class will create all widgets for UI.
        def __init__(self, master=None):
            Frame.__init__(self, master)
            self.master.title('Configuración General')
            self.master.geometry('402x311')
            self.createWidgets()
    
        def createWidgets(self):
            self.top = self.winfo_toplevel()
    
            self.style = Style()
    
            self.cmd_RegresarVar = StringVar(value='Regresar')
            self.style.configure('Tcmd_Regresar.TButton', font=('MS Sans Serif',14))
            self.cmd_Regresar = Button(self.top, text='Regresar', textvariable=self.cmd_RegresarVar, command=self.cmd_Regresar_Cmd, style='Tcmd_Regresar.TButton')
            self.cmd_Regresar.setText = lambda x: self.cmd_RegresarVar.set(x)
            self.cmd_Regresar.text = lambda : self.cmd_RegresarVar.get()
            self.cmd_Regresar.place(relx=0.597, rely=0.643, relwidth=0.301, relheight=0.209)
    
            self.cmd_GuardarVar = StringVar(value='Guardar')
            self.style.configure('Tcmd_Guardar.TButton', font=('MS Sans Serif',14))
            self.cmd_Guardar = Button(self.top, text='Guardar', textvariable=self.cmd_GuardarVar, command=self.cmd_Guardar_Cmd, style='Tcmd_Guardar.TButton')
            self.cmd_Guardar.setText = lambda x: self.cmd_GuardarVar.set(x)
            self.cmd_Guardar.text = lambda : self.cmd_GuardarVar.get()
            self.cmd_Guardar.place(relx=0.08, rely=0.643, relwidth=0.301, relheight=0.209)
    
            self.txt_EmailAdminVar = StringVar(value='')
            self.txt_EmailAdmin = Entry(self.top, textvariable=self.txt_EmailAdminVar, font=('MS Sans Serif',12))
            self.txt_EmailAdmin.setText = lambda x: self.txt_EmailAdminVar.set(x)
            self.txt_EmailAdmin.text = lambda : self.txt_EmailAdminVar.get()
            self.txt_EmailAdmin.place(relx=0.517, rely=0.437, relwidth=0.42, relheight=0.08)
    
            self.txt_NombreAdminVar = StringVar(value='')
            self.txt_NombreAdmin = Entry(self.top, textvariable=self.txt_NombreAdminVar, font=('MS Sans Serif',12))
            self.txt_NombreAdmin.setText = lambda x: self.txt_NombreAdminVar.set(x)
            self.txt_NombreAdmin.text = lambda : self.txt_NombreAdminVar.get()
            self.txt_NombreAdmin.place(relx=0.517, rely=0.283, relwidth=0.42, relheight=0.08)
    
            self.lbl_EmailAdminVar = StringVar(value='Correo electrónico:')
            self.style.configure('Tlbl_EmailAdmin.TLabel', anchor='w', font=('MS Sans Serif',12))
            self.lbl_EmailAdmin = Label(self.top, text='Correo electrónico:', textvariable=self.lbl_EmailAdminVar, style='Tlbl_EmailAdmin.TLabel')
            self.lbl_EmailAdmin.setText = lambda x: self.lbl_EmailAdminVar.set(x)
            self.lbl_EmailAdmin.text = lambda : self.lbl_EmailAdminVar.get()
            self.lbl_EmailAdmin.place(relx=0.06, rely=0.444, relwidth=0.42, relheight=0.068)
    
            self.lbl_NombreAdminVar = StringVar(value='Nombre administrador:')
            self.style.configure('Tlbl_NombreAdmin.TLabel', anchor='w', font=('MS Sans Serif',12))
            self.lbl_NombreAdmin = Label(self.top, text='Nombre administrador:', textvariable=self.lbl_NombreAdminVar, style='Tlbl_NombreAdmin.TLabel')
            self.lbl_NombreAdmin.setText = lambda x: self.lbl_NombreAdminVar.set(x)
            self.lbl_NombreAdmin.text = lambda : self.lbl_NombreAdminVar.get()
            self.lbl_NombreAdmin.place(relx=0.06, rely=0.289, relwidth=0.42, relheight=0.068)
    
            self.lbl_TituloVar = StringVar(value='Configuración General')
            self.style.configure('Tlbl_Titulo.TLabel', anchor='w', font=('MS Sans Serif',18,'bold'))
            self.lbl_Titulo = Label(self.top, text='Configuración General', textvariable=self.lbl_TituloVar, style='Tlbl_Titulo.TLabel')
            self.lbl_Titulo.setText = lambda x: self.lbl_TituloVar.set(x)
            self.lbl_Titulo.text = lambda : self.lbl_TituloVar.get()
            self.lbl_Titulo.place(relx=0.04, rely=0.051, relwidth=0.719, relheight=0.132)
    
            self.codigoAdmin = 0
    
    
    class Application(Application_ui):
        #The class will implement callback function for events and your logical code.
        def __init__(self, master=None):
            Application_ui.__init__(self, master)
            self.BuscarConfBD(self)
    
        def cmd_Regresar_Cmd(self, event=None):
            Configuraciones.Application()
    
        def cmd_Guardar_Cmd(self, event=None):
            Transacciones.GuardarConfGeneral(self.txt_NombreAdminVar.get(), self.txt_EmailAdminVar.get(), self.codigoAdmin)
            self.BuscarConfBD(self)
    
        def BuscarConfBD(self, event=None):
            registro = Transacciones.BuscarConfGeneral()
    
            for dato in registro:
                self.codigoAdmin = dato[0]
                self.txt_NombreAdminVar.set(dato[1])
                self.txt_EmailAdminVar.set(dato[2])
    
    if __name__ == "__main__":
        top = Tk()
        Application(top).mainloop()

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Hi people, I have solve the issue already. For anyone who need it, the solution was to destroy the window before the call to the new one. Example: ```python def cmd_Regresar_Cmd(self, event=None): self.master.destroy() Configuraciones.Application() ``` – Javier Maestre Nov 15 '22 at 22:54

0 Answers0