1
Hail to you guys, I’m trying to make a program with Gtk+ (python3) to save some information in a comic book but I also want to identify users by login, (Quick explanation on how the program works). The user executes the program (opens a screen), enters the information and presses the login button, in that the window closes, and the window where the data would be presented appears, until then without problems however, I want to make a button to "end session" and as soon as pressed, the login window should be presented again but I’m not sure how to do this because if I put "self.set_visible(True)" right after the second window opens, the login window returns to appear even without the data window being closed. ps: The program is pretty raw yet why I want to solve this part first for dps to continue.
Login.py
import gi
from Index import Index
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
class LoginWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Contas")
self.set_size_request(400, 600)
self.set_gravity(Gdk.Gravity.CENTER)
self.set_resizable(False)
# Grid
grid = Gtk.Grid()
self.add(grid)
self.login_txt = Gtk.Entry()
self.login_txt.set_placeholder_text("Login")
self.senha_txt = Gtk.Entry()
self.senha_txt.set_placeholder_text("Senha")
self.login_btn = Gtk.Button(label="Login")
self.login_btn.connect("clicked", self.login)
self.set_focus(self.login_btn)
grid.add(self.login_txt)
grid.attach_next_to(self.senha_txt, self.login_txt, Gtk.PositionType.BOTTOM, 1, 2)
grid.attach_next_to(self.login_btn, self.senha_txt, Gtk.PositionType.BOTTOM, 1, 2)
# sqlite
def login(self, widget):
self.hide()
oi = Index()
def main():
win = LoginWin()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == '__main__':
main()
Index.py
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class Index(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Table")
self.set_size_request(300, 200)
self.set_visible(True)
grid = Gtk.Grid()
self.add(grid)
self.button = Gtk.Button(label="Encerrar sessao")
self.button.connect("clicked", self.close)
grid.add(self.button)
self.show_all()
self.connect("destroy", Gtk.main_quit)
def close(self, widget):
self.destroy()
Dear I appreciate your help, I am dealing with Gui for a short time and so my knowledge is still very limited, but with your answer I can already have an idea of how to work with multiple windows. ps: In a change I made recently in the code I was able to do what I wanted but I believe it was not the most professional way to do it because I was just hiding the windows and it increased the memory consumption right ?
– Guilherme Seganzerla
That’s right, if the window doesn’t need to be pre-loaded or filled in it is better to destroy it so it doesn’t keep allocating memory.
– Renato Cruz
Renato, man I came across another doubt about this same project, will you give me a help kk
– Guilherme Seganzerla