python - 单击按钮时如何在 Tkinter 中弹出?

标签 python popup tkinter

单击按钮时如何在 Tkinter 中弹出窗口?单击“关于”按钮时,我想要一个带有免责声明+关于文本的弹出窗口。

我试图设置一个 def 方法,但它一定是错误的,因为它没有按我希望的那样工作。非常感谢任何帮助。

谢谢

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()

最佳答案

如果您想在新窗口中显示文本,请创建一个 Toplevel 小部件并将其用作关于文本和免责声明标签的父级。

顺便说一句,如果您有静态文本,则不需要 Tkinter 变量,因此在这种情况下,您可以简单地摆脱它们并用多行字符串替换它们:

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()

关于python - 单击按钮时如何在 Tkinter 中弹出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17261028/

相关文章:

python - 如何从 Countvectorizer token_pattern 中保留 #hashtag 和 @mention 特征符

python - 为什么 Tkinter.Tk() 不立即打开窗口?

Python/Turtle/Tkinter : in which object or sub-module the list of all symbolic color names can be found?

python - 如何将数据框附加到现有的 Excel 工作表?

python - 您可以使用 Jenkins 远程触发运行您的存储库中的脚本吗(该脚本与构建无关)

iphone - 如何像弹出窗口一样打开一个新的uiview?

css - 如何给div添加滚动条?

mysql - SQL 表中的 Tkinter 下拉菜单

Python - pyad 创建名称中带有逗号的用户

如果使用特定浏览器不起作用,PHP if else 语句会打开一个模式?