Alert boxes in Python?
This will be run in Windows, Most likely XP but 2000 and Vista are also very real possibilities.
This is intended to run in the background and alert the user when certain conditions are met, I figure that the easiest way to alert the user would be to produce a pop-up, as it needs to be handled immediately, and other options such as just logging, or sending an email are not efficient enough.
Asked by: Marcus384 | Posted: 05-10-2021
what about this:
import win32api win32api.MessageBox(0, 'hello', 'title')
win32api.MessageBox(0, 'hello', 'title', 0x00001000)
will make the box appear on top of other windows, for urgent messages. See MessageBox function for other options.Answered by: Joyce165 | Posted: 06-11-2021
For those of us looking for a purely Python option that doesn't interface with Windows and is platform independent, I went for the option listed on the following website:
# Python 3.x code # Imports import tkinter from tkinter import messagebox # This code is to hide the main tkinter window root = tkinter.Tk() root.withdraw() # Message Box messagebox.showinfo("Title", "Message")
You can choose to show various types of messagebox options for different scenarios:
- showerror ()
- askyesno ()
- askretrycancel ()
edited code per my comment belowAnswered by: Anna238 | Posted: 06-11-2021
GTK may be a better option, as it is cross-platform. It'll work great on Ubuntu, and should work just fine on Windows when GTK and Python bindings are installed.
from gi.repository import Gtk dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "This is an INFO MessageDialog") dialog.format_secondary_text( "And this is the secondary text that explains things.") dialog.run() print "INFO dialog closed"
The arguments passed should be the gtk.window parent (or None), DestroyWithParent, Message type, Message-buttons, title.Answered by: Ada778 | Posted: 06-11-2021
You can use PyAutoGui to make alert boxes First install pyautogui with pip:
pip install pyautogui
Then type this in python:
import pyautogui as pag pag.alert(text="Hello World", title="The Hello World Box")
With Ok and Cancel Button
With Text Input
password()With Text Input, but typed characters will be appeared as *
You can use win32 library in Python, this is classical example of OK or Cancel.
import win32api import win32com.client import pythoncom result = win32api.MessageBox(None,"Do you want to open a file?", "title",1) if result == 1: print 'Ok' elif result == 2: print 'cancel'
Answered by: Catherine784 | Posted: 06-11-2021
win32api.MessageBox(0,"msgbox", "title") win32api.MessageBox(0,"ok cancel?", "title",1) win32api.MessageBox(0,"abort retry ignore?", "title",2) win32api.MessageBox(0,"yes no cancel?", "title",3)
Start an app as a background process that either has a TCP port bound to localhost, or communicates through a file -- your daemon has the file open, and then you
echo "foo" > c:\your\file. After, say, 1 second of no activity, you display the message and truncate the file.
python - Alert pop up does not go away
I am automating a webpage where after refreshing, Chrome throws a confirmation pop-up to reload, I am handling this using driver.switch_to.alert.accept(). The problem is that even after the alert is accepted, the pop up still remains on the webpage. My script proceeds further but fails since no action can be done until the pop is gone. Any help would be greatly appreciated. I am using Python and selenium to au...
How can I use a DLL file from Python?
What is the easiest way to use a DLL file from within Python? Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python? Native Python functionality is strongly preferred over using a third-party library.
python - PubSub lib for c#
Is there a c# library which provides similar functionality to the Python PubSub library? I think it's kind of an Observer Pattern which allows me to subscribe for messages of a given topic instead of using events.
python - What is the best way to copy a list?
This question already has answers here:
python - Possible Google Riddle?
My friend was given this free google website optimizer tshirt and came to me to try and figure out what the front logo meant. t-shirt So, I have a couple of guesses as to what it means, but I was just wondering if there is something more. My first guess is that eac...
How do you check whether a python method is bound or not?
Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to?
ssh - How to scp in Python?
What's the most pythonic way to scp a file in Python? The only route I'm aware of is os.system('scp "%s" "%s:%s"' % (localfile, remotehost, remotefile) ) which is a hack, and which doesn't work outside Linux-like systems, and which needs help from the Pexpect module to avoid password prompts unless you already have passwordless SSH set up to the remote host. I'm aware of Twisted'...
python - How do I create a new signal in pygtk
I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object.
python - What do I need to import to gain access to my models?
I'd like to run a script to populate my database. I'd like to access it through the Django database API. The only problem is that I don't know what I would need to import to gain access to this. How can this be achieved?
python - How do I edit and delete data in Django?
I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change_form?! or something), EDIT it and save it back to the DB. Secondly how do I DELETE the data that's in the DB? i.e. search, select and then delete! Please show me an example of the code ...