How to make a popup in Tkinter when a button is clicked?

How to make a popup in Tkinter when a button is clicked? When the "About" button is clicked, I want to pop up with a refusal + text message.

I tried to configure the def method, but it should be very wrong, because it does not work as I would like. Any help would be greatly appreciated.

thanks

import sys from Tkinter import * def clickAbout(): name = ("Thanks for the click") return app = Tk() app.title("SPIES") app.geometry("500x300+200+200") labelText = StringVar() labelText.set ("Please browse to the directory you wish to scan") labelText2 = StringVar() labelText2.set ("About \n \n \ SPIES will search your chosen directory for photographs containing \n \ GPS information. SPIES will then plot the co-ordinates on Google \n \ maps so you can see where each photograph was taken.") labelText3 = StringVar() labelText3.set ("\n Disclaimer \n \n \ Simon Portable iPhone Exif-extraction Software (SPIES) \n \ software was made by Simon. This software \n \ comes with no guarantee. Use at your own risk") label1 = Label(app, textvariable=labelText, height=0, width=100) label1.pack() label1 = Label(app, textvariable=labelText2, height=0, width=100) label1.pack() label = Label(app, textvariable=labelText3, height=0, width=100) label.pack() b = Button(app, text="Quit", width=20, command=app.destroy) b.pack(side='bottom',padx=0,pady=0) button1 = Button(app, text="About SPIES", width=20, command=clickAbout) button1.pack(side='bottom',padx=5,pady=5) app.mainloop() 
+8
python tkinter popup
source share
1 answer

If you want to display the text in a new window, create a Toplevel widget and use it as the parent element of the labels for the text and disclaimer.

By the way, Tkinter variables are not needed if you have static text, so in this case you can just get rid of them and replace them with multi-line strings:

 import sys from Tkinter import * ABOUT_TEXT = """About SPIES will search your chosen directory for photographs containing GPS information. SPIES will then plot the co-ordinates on Google maps so you can see where each photograph was taken.""" DISCLAIMER = """ Disclaimer Simon Portable iPhone Exif-extraction Software (SPIES) software was made by Simon. This software comes with no guarantee. Use at your own risk""" def clickAbout(): toplevel = Toplevel() label1 = Label(toplevel, text=ABOUT_TEXT, height=0, width=100) label1.pack() label2 = Label(toplevel, text=DISCLAIMER, height=0, width=100) label2.pack() app = Tk() app.title("SPIES") app.geometry("500x300+200+200") label = Label(app, text="Please browse to the directory you wish to scan", height=0, width=100) b = Button(app, text="Quit", width=20, command=app.destroy) button1 = Button(app, text="About SPIES", width=20, command=clickAbout) label.pack() b.pack(side='bottom',padx=0,pady=0) button1.pack(side='bottom',padx=5,pady=5) app.mainloop() 
+14
source share

All Articles