Skip to content

Dialogs (such as messagebox) block async mainloop  #39

Description

@insolor

In the following code (pure tkinter) counter continues to work while messagebox dialog is shown:

import tkinter as tk
from tkinter import messagebox

root = tk.Tk()


def loop():
    counter.set(counter.get() + 1)
    root.after(1000, loop)


def show_message():
    messagebox.showinfo("Info", "Some info")


counter = tk.IntVar()
tk.Label(root, textvariable=counter).pack()

tk.Button(root, text="Start counter", command=loop).pack()
tk.Button(root, text="Show message", command=show_message).pack()

root.mainloop()

But with the corresponding code with async_tkinter_loop counter is paused when messagebox is shown:

import asyncio
import tkinter as tk
from tkinter import messagebox
from async_tkinter_loop import async_mainloop, async_handler

root = tk.Tk()


@async_handler
async def loop():
    while True:
        counter.set(counter.get() + 1)
        await asyncio.sleep(1.0)


def show_message():
    messagebox.showinfo("Info", "Some info")


counter = tk.IntVar()
tk.Label(root, textvariable=counter).pack()

tk.Button(root, text="Start counter", command=loop).pack()
tk.Button(root, text="Show message", command=show_message).pack()

async_mainloop(root)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions