所以我在Python 3.6中编写了一个应用程序,但我似乎找不到如何获取消息框答案值(是或否)的答案。
fileSavedExit = True
def msgbox1():
if fileSavedExit == True:
root.destroy()
if fileSavedExit == False:
messagebox.askyesno('Save File ?','Do you want to save the file first?')
这样的事情。我正在寻找可以保存答案的代码('Yes'
或'No'
)。如果有人能帮助我,我将感激不尽。 :o
答案 0 :(得分:0)
askyesno
,那么 True
会返回"Yes"
,如果答案是False
,则"No"
会返回if/else
。您只需使用try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
import tkinter.messagebox as tkmb
except ImportError:
import Tkinter as tk
import tkMessageBox as tkmb
def ask():
response = tkmb.askyesno("Messagebox Title", "Is this it?")
global button
if response: # If the answer was "Yes" response is True
button['text'] = "Yes"
else: # If the answer was "No" response is False
button['text'] = "No"
if __name__ == '__main__':
root = tk.Tk()
button = tk.Button(root, text="Ask...", command=ask)
button.pack()
tk.mainloop()
过滤它。
css-grid