Llevo algún tiempo aprendiendo de forma autodidacta Python y estoy intentando crear una interfaz gráfica con varias ventanas. Tengo una ventana principal con 3 botones que al presionar me crea otra ventana con otras opciones (aun en construcción...) pero por el momento me minimiza la principal con iconify()
pero me gustaría que al cerrar la nueva ventana abierta volviera a aparecer la principal, como también no me dejara crear mas de 1 ventana secundaria. Me refiero, que si ya hay 1 ventana secundaria (de ruleta, blackjack o poker) no me dejara crear otra sin cerrar esta última. Espero haberme explicado bien.
No se si es la forma adecuada y probablemente el código no esté escrito de una forma correcta pero aquí os dejo el código de la ventana principal y el de 1 secundaria, pues las 3 secundarias mas o menos tienen lo mismo:
Ventana principal
from tkinter import *
from Ventana_ruleta import VentanaRuleta
from Ventana_bj import VentanaBlackjack
from Ventana_pk import VentanaPoker
class VentanaPrincipal:
def __init__(self):
#---Creamos y configuramos la ventana principal
self.ventana_inicio = Tk()
self.ventana_inicio.title("Ventana Principal")
self.ventana_inicio.geometry("650x400")
self.ventana_inicio.resizable(0,0)
#---Creamos el frame con el titulo
self.frame_titulo = Frame(self.ventana_inicio)
self.frame_titulo.pack(side=TOP)
self.frame_titulo.config(width=650,height=125)
self.frame_titulo.pack_propagate(False) #Le decimos al Frame que no se amolde al label
#---Creamos el Label del titulo
self.label_titulo = Label(self.frame_titulo, text="Practicas Croupier")
self.label_titulo.pack(anchor = CENTER)
self.label_titulo.config(font=("Verdana", 32))
self.label_titulo.config(padx=45, pady=45)
#---Creamos el Frame con el subtítulo
self.frame_subtitulo = Frame(self.ventana_inicio)
self.frame_subtitulo.pack()
self.frame_subtitulo.config(width=650, height=75)
self.frame_subtitulo.pack_propagate(False)
#---Creamos el Label del subtitulo
self.label_subtitulo = Label(self.frame_subtitulo, text="Selecciona el juego")
self.label_subtitulo.pack(anchor=CENTER)
self.label_subtitulo.config(font=("Courier New", 24))
self.label_subtitulo.config(padx=25, pady=25)
#---Creamos la funcion de los botones
def llama_ventana_ruleta():
self.ventana_inicio.iconify()
self.ventana_ruleta = VentanaRuleta()
def llama_ventana_bj():
self.ventana_inicio.iconify()
self.ventana_bj = VentanaBlackjack()
def llama_ventana_pk():
self.ventana_inicio.iconify()
self.ventana_pk = VentanaPoker()
#---Creamos los botones
self.boton_ruleta = Button(self.ventana_inicio, width=25, height=5, text="Ruleta", command = llama_ventana_ruleta)
self.boton_bj = Button(self.ventana_inicio, width=25, height=5, text="BlackJack", command = llama_ventana_bj)
self.boton_pk = Button(self.ventana_inicio, width=25, height=5, text="Poker", command = llama_ventana_pk)
self.boton_ruleta.place(x=30,y=250)
self.boton_bj.place(x=230, y=250)
self.boton_pk.place(x=430, y=250)
self.ventana_inicio.mainloop()
vp = VentanaPrincipal()
Ventana secundaria
from tkinter import *
class VentanaRuleta:
def __init__(self):
#---Creamos la ventana de ruleta
self.v_ruleta = Tk()
self.v_ruleta.title("Ruleta Americana")
self.v_ruleta.geometry("650x400")
self.v_ruleta.resizable(0,0)
#---Creamos el frame con el titulo
self.frame_titulo = Frame(self.v_ruleta)
self.frame_titulo.pack(side=TOP)
self.frame_titulo.config(width=650,height=115)
self.frame_titulo.pack_propagate(False) #Le decimos al Frame que no se amolde al label
self.frame_titulo.config(relief="sunken", bd=10)
#---Creamos el label con el titulo
self.label_subtitulo = Label(self.frame_titulo, text="Selecciona el tema a practicar o consultar")
self.label_subtitulo.place(x=5,y=20)
self.label_subtitulo.config(font=("Courier New", 18))
self.label_subtitulo.config(padx=15, pady=15)
#---Creamos el frame de botones
self.frame_botones = Frame(self.v_ruleta)
self.frame_botones.pack()
self.frame_botones.config(width=650,height=300)
#---Creamos botones
self.boton_volver = Button(self.frame_botones, width = 17, height=2, text="Volver")
self.boton_vecinos = Button(self.frame_botones, width = 17, height = 3, text="Vecinos")
self.boton_figuras = Button(self.frame_botones, width = 17, height = 3, text="Figuras")
self.boton_examen = Button(self.frame_botones, width = 17, height = 3, text="Examen")
self.boton_calculadora = Button(self.frame_botones, width = 17, height = 3, text="Calculadora")
#---Colocamos los botones
self.boton_vecinos.grid(row = 0, column = 0)
self.boton_examen.grid(row = 2, column = 0)
self.boton_volver.grid(row = 1, column = 1)
self.boton_figuras.grid(row = 0, column = 2)
self.boton_calculadora.grid(row = 2, column = 2)
#---Les damos distancia a los botones
self.boton_vecinos.config(pady=20, padx=20, bd=5)
self.boton_examen.config(pady=20, padx=20, bd=5)
self.boton_volver.config(pady=20, padx=20, bd=5)
self.boton_figuras.config(pady=20, padx=20, bd=5)
self.boton_calculadora.config(pady=20, padx=20, bd=5)
#self.v_ruleta.mainloop()
Espero que no se vean muchas barbaridades y no asuste mucho el código, pido disculpas de antemano... jajajajaja Un saludo y muchas gracias!