+ 13

Are there alert boxes like in JS in Python?

In JS you can do alert("Sample") And it will make an alert come up on the page. I know Python isn't web and it may not make sense but can you do this in a program or something?

29th Sep 2018, 11:52 PM
DrChicken24
DrChicken24 - avatar
16 Answers
+ 20
its possible with the kivy or tikner libraries. but they are not available on sololearn.
29th Sep 2018, 11:57 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 10
If you use a User interface Library in Python you can! Example using Kivy: https://kivy.org/doc/stable/api-kivy.uix.popup.html popup = Popup(title='Test popup', content=Label(text='Hello world'), auto_dismiss=False) popup.open()
29th Sep 2018, 11:59 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 10
With tkinter: import tkinter.messagebox tkinter.messagebox.showinfo(title, text) there are a lot more useful messageboxes in tkinter.messagebox
30th Sep 2018, 10:04 AM
Tim
Tim - avatar
+ 8
Implementing a GUI is not the *only* way to display the alert-box. If I remember correctly, you can also accomplish this via use of either the os module or sys module. I'll have to look into this later as this has made me curious. Lol.
2nd Oct 2018, 3:24 AM
Fox
Fox - avatar
+ 6
Arthur I ran it on pydroid. It gave a gray screen
1st Oct 2018, 11:31 PM
LONGTIE👔
LONGTIE👔 - avatar
8th Mar 2021, 5:13 PM
PASHA from Russia 🇷🇺
PASHA  from Russia  🇷🇺 - avatar
+ 5
Tim Ulisses Cruz LONGTIE👔 And I would have to download these and use IDLE or another Python editor?
30th Sep 2018, 4:28 PM
DrChicken24
DrChicken24 - avatar
+ 5
it help me too.
1st Oct 2018, 7:54 AM
Joshua Martin Fontanilla
Joshua Martin Fontanilla - avatar
+ 5
Kivy, PyQt5... thats what i know
1st Oct 2018, 4:52 PM
danvetio
danvetio - avatar
+ 4
Ok, thanks
30th Sep 2018, 6:22 PM
DrChicken24
DrChicken24 - avatar
+ 4
DrChicken24 In tkinter from tkinter import * window = Tk() alert = Tk() def exit(): exit() def alert(): x = Label(alert,text = "Hello world") x.pack() Okay = Button(alert,text = "exit",witdth = 20,bg = "red",command = exit) Okay.pack() alert.mainloop() Button = Button(window,text = "Alert",bg = "green",width = 20, command = alert) window.geometry("500x400+200+200") Button.pack() window.mainloop() I did it on my way, i dont think there is a method for doing that
1st Oct 2018, 11:01 PM
I Am Arthur
I Am Arthur - avatar
+ 3
tkinter is in the standart library. So it works on every machine with python except SoloLearn.
30th Sep 2018, 6:05 PM
Tim
Tim - avatar
+ 3
from kivy.app import App from kivy.uix.popup import Popup from kivy.uix.button import Button from kivy.uix.floatlayout import FloatLayout from kivy.factory import Factory class Example(FloatLayout): def __init__(self, **kwargs): super().__init__(**kwargs) self.init_popup() def init_popup(self): # create content popup (ObjectReference) content = Button( text='Close', size_hint=(.2, .1) ) # create a popup window popup = Popup( title='Test Popup', content=content, size_hint=(None, None), size=(400, 400), auto_dismiss=False ) # close popup content.bind(on_press=lambda instance:popup.dismiss()) button = Button( text='Show Popup', size_hint=(None, None), size=(200, 50), pos_hint={'center_x': 0.5, 'center_y': 0.5} ) button.bind(on_release=lambda instance:popup.open()) self.add_widget(button) class ExampleApp(App): title = 'Popup Example' def build(self): return Example() ExampleApp().run()
2nd Oct 2018, 9:18 AM
danvetio
danvetio - avatar
+ 2
LONGTIE👔 Pydroid cant create two windowns, only one The gray screen is the button who when pressed creat another window(the alert) with a red button to close the window
1st Oct 2018, 11:40 PM
I Am Arthur
I Am Arthur - avatar
+ 1
Tim Can you do this in a actual code for me?
1st Oct 2018, 11:29 PM
I Am Arthur
I Am Arthur - avatar
0
In django or flask we will written HTML, CSS, JS Anyone programming language in python
2nd Oct 2018, 4:11 AM
Jokerkarthi
Jokerkarthi - avatar