Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a pop up in Tkinter when a button is clicked?

How do I make a pop-up in Tkinter when a button is clicked? When the 'About' button is clicked, I want a pop up with the disclaimer + about text.

I have tried to set up a def method but it must be very wrong because it's not working as I would like. Any help would be very much appreciated.

Thank you

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's 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()
like image 308
Bob Uni Avatar asked Jun 23 '13 13:06

Bob Uni


People also ask

How do I create a pop up notification in Python?

In order to create a Python popup message, you can use Tkinter message prompts. First, you need to import the Tkinter package to use this method. The Tkinter message box module offers different options and configurations.

What does Mainloop () do in Tkinter?

window.mainloop() tells Python to run the Tkinter event loop. This method listens for events, such as button clicks or keypresses, and blocks any code that comes after it from running until you close the window where you called the method.

What is BD in button Tkinter?

Tkinter Button bd option sets width or stroke of the border around the outside of the button. In this tutorial, we will learn how to use bd (border) option and change the width of the border for button.


1 Answers

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

By the way, Tkinter variables are not necessary if you have static text, so in this case you can simply get rid of them and replace them with multiline 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's 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()
like image 151
A. Rodas Avatar answered Oct 15 '22 01:10

A. Rodas