Tkinter Python screens

Asked

Viewed 543 times

-2

from tkinter import *
import Saque

#Propriedades da Janela Principal
JanMenu = Tk() #JanMenu é uma instância da Classe Tk;
JanMenu['bg'] = 'white' #Cor de Fundo da Janela = Branco
JanMenu.geometry("400x500+500+120")
JanMenu.resizable(width=False , height=False)
JanMenu.overrideredirect(True)

def abrir():
    Saque.JanSaque.mainloop();

BtSaque = Button(FrmMenu, image = saque, bd = 0, cursor = 'hand2', bg = 'white', 
                                     command = abrir); #Botão saque
BtSaque.grid (row = 3, column = 0, pady = (20, 0), padx = (0, 250));

JanMenu.mainloop()

I have this main window and I want when I click the button BtSaque open the window to JanSaque which is a instância of Tk that’s in the file Saque.py, but when I run the program it opens both screens at the same time. Can anyone help me? I just want to open another window after clicking the button. Thank you.

  • 1

    The question is not clear enough. If there is another file besides this one, then there should be no other code sequence than this?

  • what is in the other file are just the widgets of your screen, what I want is that on this screen I can call this other file (that is a screen) after clicking on btSaque. This code make open another screen after on the button was that I could not do.

1 answer

0

Tk opens a window when you create an instance of it and not in the mainloop() method. You need to instantiate Tk within the constructor of the Serve class and when you click the open() function create an instance of the Serve class

Example:

class Saque:
  def __init__(self):
    self.JanSaque = Tk()
    ...

And on the button create a Withdrawal instance:

def abrir():
  s = Saque()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.