Ive been trying to do this for a while now, but haven't figured out a way to do it.
I have a tkinter script, that creates a popup window when a button is pressed. However I don't want the user to be able to click away from this window to any previous windows created. I have got this working with root.grab_set(), however there is no indication to the user that they must stay on that window.
class popup(object):
def __init__(self, parent):
self.root=Toplevel(parent)
self.root.grab_set() #prevents the user clicking on the parent window
#But the window doesnt 'flash' when an attempt to click away is made
For example, when you have a window created by the filedialogue module, if you attempt to click onto another window the filedialogue window stays on top and has a 'flashing' animation to let the user know they cant click away. Is there a way I can reproduce this effect? Going through the source of filedialogue hasn't been fruitful for me, and neither have Google searches.
How do I make a pop-up in Tkinter when a button is clicked? Popup window in Tkinter can be created by defining the Toplevel (win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.
To create a Frameless window, we will use the overrideredirect () method. To create a Frameless Window, we will pass value True or 1 as arguments in over ride redirect () method. Below is the program that creates a normal tkinter window.
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python.
It is a standard Python interface to the Tk GUI toolkit shipped with Python. To create a Frameless window, we will use the overrideredirect () method. To create a Frameless Window, we will pass value True or 1 as arguments in over ride redirect () method.
The simplest way i can think to do this is to use an event and the focus commands, along with the windows bell
command:
#!python3
import tkinter as tk
class popup(object):
def __init__(self, parent):
self.root=tk.Toplevel(parent)
self.root.title("Popup")
self.root.bind("<FocusOut>", self.Alarm)
def Alarm(self, event):
self.root.focus_force()
self.root.bell()
main = tk.Tk()
main.title("Main")
pop = popup(main)
main.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With