0

I use tkinter and CTK: I have created a page for login and I want to stop or use this page when the user is logged in, I want to show a new window and I want to resume the window when I want? How can I do that, I didn't know how to make it

2 Answers2

0

If you mean you want to open up another window to do something before going back to the original window, you should consider using message box. Here is a link that goes over the types of messageboxes: https://docs.python.org/3/library/tkinter.messagebox.html.

coderz
  • 1
  • NO, i want to pause original window , and i make another window main . – Ahmed Hassan Feb 08 '23 at 23:43
  • You could create a new page and .destroy() the old one. I recommend looking at this stack overflow page which explains how to do that. https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter – coderz Feb 09 '23 at 00:08
  • when i destroy original window , app colsed ! and i want to comback this page in another time you can understand me ? – Ahmed Hassan Feb 09 '23 at 01:09
  • So correct me if I'm wrong. You want to keep the old window but carry on through different tasks with a new window right? here are some links on how to open a new window since a cant publish code in a reply: https://www.geeksforgeeks.org/open-a-new-window-with-a-button-in-python-tkinter/ or https://stackoverflow.com/questions/15363923/disable-the-underlying-window-when-a-popup-is-created-in-python-tkinter – coderz Feb 09 '23 at 21:25
0

I'll bite. Here's an example application that opens a second window when the user clicks a button on the main window, and disables interaction with the main window until the second window is closed.

Some configuration has been omitted for brevity, and I'm not using CTk here because I don't know how you've implemented it in your specific application - however, it should be easy enough to modify this example to work with CTk.

import tkinter as tk
from tkinter import ttk


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.open_button = ttk.Button(
            self,
            text='Open 2nd Window',
            command=self.modal
        )
        self.open_button.pack()

    def modal(self):
        self.window = tk.Toplevel(self)  # create new window
        # bind a handler for when the user closes this window
        self.window.protocol('WM_DELETE_WINDOW', self.on_close)
        # disable interaction with the main (root) window
        self.attributes('-disabled', True)
        self.close_button = ttk.Button(
            self.window, 
            text='Close Modal', 
            command=self.on_close
        )
        self.close_button.pack()

    def on_close(self):
        # re-enable interaction the root window
        self.attributes('-disabled', False)
        # close the modal window
        self.window.destroy()


if __name__ == '__main__':
    app = App()
    app.mailoop()  # run the app        

In the future:

  1. Provide code that shows you made a good-faith effort to solve the problem on your own
  2. Don't post the same question multiple times within hours - if you need to make changes, edit the original question
JRiggles
  • 4,847
  • 1
  • 12
  • 27