def specialSeven(event):
#gets only the mp3 audio file of the video
canvas = event.widget.canvas
try:
clip = AudioFileClip(canvas.message)
title = 'Get Audio'
message = 'Would you like to retrieve the audio file for this video?'
answer = tkMessageBox.askquestion(title,message)
if answer == 'yes':
name = 'new-'+os.path.basename(canvas.message)
name2 = name.replace('.mp4','.mp3')
clip.to_audiofile(name2)
canvas.message = 'new-'+canvas.display
canvas.display = 'new-'+canvas.display
except:
canvas.condition=4
canvas.create_text(250,10,text='Please Try Again')
redrawAll(canvas)
python类askquestion()的实例源码
def editSeven(event):
canvas = event.widget.canvas
try:
title = 'Remove Audio'
message = "Would you like to remove the audio?"
answer = tkMessageBox.askquestion(title=title,message=message)
if answer == 'yes':
video=VideoFileClip(canvas.message)
audioless=video.without_audio()
name = 'new-'+os.path.basename(canvas.message)
audioless.write_videofile(name)
canvas.message = 'new-'+canvas.display
canvas.display = 'new-'+canvas.display
except:
canvas.create_text(250,10,text='Please Try Again')
redrawAll(canvas)
def questionBox(self, title, message):
self.topLevel.update_idletasks()
return MessageBox.askquestion(title, message)
def do_lose_action(real=False):
# Cause the game to lose.
answer = tkMessageBox.askquestion('GAME OVER', 'Do you want to try again?')
graph.after_cancel(frame_handle if real else blink_handle)
graph.delete(ALL)
if answer == 'yes':
initialise()
else:
high_score_table()
################################################################################
# VECTOR MATHEMATICS CLASS
def questionBox(self, title, message):
self.topLevel.update_idletasks()
return MessageBox.askquestion(title, message)
def MsgBox(title, text, style):
box = [
msg.showinfo, msg.showwarning, msg.showerror,
msg.askquestion, msg.askyesno, msg.askokcancel, msg.askretrycancel,
];
tk.Tk().withdraw(); #Hide Main Window.
if style in range(7):
return box[style](title, text)
def MsgBox(title, text, style):
box = [
msg.showinfo, msg.showwarning, msg.showerror,
msg.askquestion, msg.askyesno, msg.askokcancel, msg.askretrycancel,
];
tk.Tk().withdraw(); #Hide Main Window.
if style in range(7):
return box[style](title, text)
def ask_question(self, title, message):
return messagebox.askquestion(title, message)
def ask_question(self, title, message):
return messagebox.askquestion(title, message)
def loop(self):
"""This is an explict replacement for _tkinter mainloop()
It lets you catch keyboard interrupts easier, and avoids
the 20 msec. dead sleep() which burns a constant CPU."""
while self.exit < 0:
# There are 2 whiles here. The outer one lets you continue
# after a ^C interrupt.
try:
# This is the replacement for _tkinter mainloop()
# It blocks waiting for the next Tcl event using select.
while self.exit < 0:
self.root.tk.dooneevent(TCL_ALL_EVENTS)
except SystemExit:
# Tkinter uses SystemExit to exit
#print 'Exit'
self.exit = 1
return
except KeyboardInterrupt:
if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
# self.tk.eval('exit')
self.exit = 1
return
continue
except:
# Otherwise it's some other error - be nice and say why
t, v, tb = sys.exc_info()
text = ""
for line in traceback.format_exception(t,v,tb):
text += line + '\n'
try: tkMessageBox.showerror ('Error', text)
except: pass
self.exit = 1
raise SystemExit, 1
def _WriteSlaveAddress(self, id):
q = tkMessageBox.askquestion('Address update','Are you sure you want to change address?', parent=self.frame)
if q == 'yes':
status = pijuice.config.SetAddress(id+1, self.slaveAddr[id].get())
if status['error'] != 'NO_ERROR':
#self.slaveAddr[id].set(status['error'])
tkMessageBox.showerror('Address update', status['error'], parent=self.frame)
else:
tkMessageBox.showinfo('Address update', "Success!", parent=self.frame)
def _WriteSlaveAddress(self, id):
q = tkMessageBox.askquestion('Address update','Are you sure you want to change address?', parent=self.frame)
if q == 'yes':
status = pijuice.config.SetAddress(id+1, self.slaveAddr[id].get())
if status['error'] != 'NO_ERROR':
#self.slaveAddr[id].set(status['error'])
tkMessageBox.showerror('Address update', status['error'], parent=self.frame)
else:
tkMessageBox.showinfo('Address update', "Success!", parent=self.frame)
def _WriteSlaveAddress(self, id):
q = tkMessageBox.askquestion('Address update','Are you sure you want to change address?', parent=self.frame)
if q == 'yes':
status = pijuice.config.SetAddress(id+1, self.slaveAddr[id].get())
if status['error'] != 'NO_ERROR':
#self.slaveAddr[id].set(status['error'])
tkMessageBox.showerror('Address update', status['error'], parent=self.frame)
else:
tkMessageBox.showinfo('Address update', "Success!", parent=self.frame)
def _WriteSlaveAddress(self, id):
q = tkMessageBox.askquestion('Address update','Are you sure you want to change address?', parent=self.frame)
if q == 'yes':
status = pijuice.config.SetAddress(id+1, self.slaveAddr[id].get())
if status['error'] != 'NO_ERROR':
#self.slaveAddr[id].set(status['error'])
tkMessageBox.showerror('Address update', status['error'], parent=self.frame)
else:
tkMessageBox.showinfo('Address update', "Success!", parent=self.frame)
def _WriteSlaveAddress(self, id):
q = tkMessageBox.askquestion('Address update','Are you sure you want to change address?', parent=self.frame)
if q == 'yes':
status = pijuice.config.SetAddress(id+1, self.slaveAddr[id].get())
if status['error'] != 'NO_ERROR':
#self.slaveAddr[id].set(status['error'])
tkMessageBox.showerror('Address update', status['error'], parent=self.frame)
else:
tkMessageBox.showinfo('Address update', "Success!", parent=self.frame)
def questionBox(self, title, message):
self.topLevel.update_idletasks()
return MessageBox.askquestion(title, message)
def QuitGame(self):
self.message=tkMessageBox.askquestion("Exit","Do you want to exit ?")
if (self.message == 'yes'):
root.destroy()
def quit():
answer = tkMessageBox.askquestion('Computer Application', 'Are you sure to EXIT?')
if answer == 'yes':
Login.quit
sys.exit()
def logout(name):
result = tkMessageBox.askquestion("Logout Confirmation", "Are you sure you want to logout?", icon='warning')
if result == 'yes':
message = "See you again, " + name + "!"
tkMessageBox.showinfo("Thank you", message)
root.destroy()
authentication.show_window()
def write_entry_db():
print 'Connecting to MySQL server'
Message = 'Connecting to MySQL server'
status = Label(topframe, text = 'Connecting to MySQL server', bd = 1, relief = SUNKEN, anchor =W)
status.grid(row = 8, sticky=N+E+S+W, columnspan = 2)
host = var_host.get()
user = var_user.get()
passwd = var_passwd.get()
db = var_dbName.get()
port = var_port.get()
port = int(port)
try:
global conn
global cur
conn=MySQLdb.connect(host,user,passwd,db,port)
cur = conn.cursor()
Message = 'Connected to MySQL server'
print 'Connected to MySQL server\n'
status = Label(topframe, text = Message, bd = 1,fg = '#228B22', relief = SUNKEN, anchor =W)
status.grid(row = 8, sticky=N+E+S+W, columnspan = 2)
status = Label(topframe, text = 'Waiting For Table Creating...', bd = 1, relief = SUNKEN, anchor =W)
status.grid(row = 9, sticky=N+E+S+W, columnspan = 2)
answer = tkMessageBox.askquestion('Computer Application', 'Server Connected, creating new tables?')
if answer == 'yes':
execfile("Creating_Table.py")
status = Label(topframe, text = 'Tables Created', fg = '#228B22', bd = 1, relief = SUNKEN, \
anchor =W)
status.grid(row = 9, sticky=N+E+S+W, columnspan = 2)
else:
execfile("Existing_Table.py")
status = Label(topframe, text = "Tables checking, if not exist, creat new table", bd = 1, \
relief = SUNKEN, anchor =W)
status.grid(row = 9, sticky=N+E+S+W, columnspan = 2)
status = Label(topframe, text = 'Table checking passed, please input the following file names', \
bd = 1,fg = '#228B22', relief = SUNKEN, anchor =W)
status.grid(row = 9, sticky=N+E+S+W, columnspan = 2)
except:
Message = 'Connection Failed! Please Check!'
print 'Connection Failed! Please Check!'
status = Label(topframe, text = Message, bd = 1 , fg = 'red',relief = SUNKEN, anchor =W)
status.grid(row = 8, sticky=N+E+S+W, columnspan = 2)