mloskot
mloskot

Reputation: 38972

Tkinter equivalent of non-blocking System.Windows.Forms.Form.Show() from .NET

(This question was originally posted to python-tkinter mailing list)

I'm trying to replicate a non-blocking (or modeless) window behaviour from a Windows .NET application using Tkinter.

The application I've got shows a new window in response to some event (might be non-GUI event) and the execution continues leaving the new window displayed.

Here is the relevant code:

private void foo(object sender, EventArgs e)
{
   Form1 f = new Form1();
   f.Show(); // displays a window and continues
   Console.WriteLine("Form created");
}

The important bit is call to the Show() method of .NET class System.Windows.Forms.Form/Control.

The foo() function may be called from a non-GUI application, as response to some signal or even invoked from a C++ application.

The point is there is no explicit waiting for events and the window is modeless.

How can I achieve similar behaviour in Tkinter? Is there any Tkinter idiomatic way to avoid calling mainloop() or wait_window() methods (which both are blocking)?

Upvotes: 1

Views: 1231

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386382

You can create a non-modal popup window by creating an instance of Toplevel (assuming you've already created the root window). However, you need to have the event loop running because that is the mechanism tkinter uses to know when the window needs to be repainted.

Upvotes: 1

Related Questions