8
單擊按鈕時如何在Tkinter中彈出一個對話框?當點擊'關於'按鈕時,我想彈出一個關於文本的免責聲明。單擊按鈕時如何在Tkinter中彈出?
我試圖設置一個def方法,但它必須是非常錯誤的,因爲它不工作,因爲我想。任何幫助將非常感激。
如果你想顯示的一個新窗口中的文本,然後創建一個Toplevel小窗口部件,並用它作爲標籤的有關文本和免責聲明的父母謝謝
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()
謝謝你,這是一個偉大幫助 –
@Bob:您可能希望在'clickAbout()'函數的末尾添加一個'toplevel.focus_force()'來激活新窗口(這就是大多數應用程序的工作方式)。 – martineau