我用它来从用户那里得到是/否,但它会打开一个空窗口:
from Tkinter import *
from tkMessageBox import *
if askyesno('Verify', 'Really quit?'):
print "ok"
而这个空窗并没有消失。我怎样才能防止这种情况?
这不起作用:
Tk().withdraw()
showinfo('OK', 'Select month')
print "line 677"
root = Tk()
root.title("Report month")
months = ["Jan","Feb","Mar"]
sel_list = []
print "line 682"
def get_sel():
sel_list.append(Lb1.curselection())
root.destroy()
def cancel():
root.destroy()
B = Button(root, text ="OK", command = get_sel)
C = Button(root, text ="Cancel", command = cancel)
Lb1 = Listbox(root, selectmode=SINGLE)
for i,j in enumerate(months):
Lb1.insert(i,j)
Lb1.pack()
B.pack()
C.pack()
print "line 702"
root.mainloop()
for i in sel_list[0]:
print months[int(i)]
return months[int(sel_list[0][0])]