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

后端 未结 1 1375
予麋鹿
予麋鹿 2021-02-14 19:31

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

相关标签:
1条回答
  • 2021-02-14 19:36

    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()
    
    0 讨论(0)
提交回复
热议问题