本文整理汇总了Python中ttk.Combobox.focus_set方法的典型用法代码示例。如果您正苦于以下问题:Python Combobox.focus_set方法的具体用法?Python Combobox.focus_set怎么用?Python Combobox.focus_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ttk.Combobox
的用法示例。
在下文中一共展示了Combobox.focus_set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoggerDialog
# 需要导入模块: from ttk import Combobox [as 别名]
# 或者: from ttk.Combobox import focus_set [as 别名]
class LoggerDialog(Toplevel):
def __init__(self, master, customers, payments, refresh):
Toplevel.__init__(self,master)
self.root = master
self.refresh = refresh
self.title("Check In")
self.iconname = "Check In"
self.name = StringVar() # variable for customer
self.customers = customers # customers object
self.payments = payments
self.names = []
self.workout = StringVar()
self.workouts = []
self.workouts_form = []
self.date = StringVar()
self.date.set(strftime("%m/%d/%Y"))
self.refresh_time = 15 # in minutes
self.output = '' # for the output label at the bottom
self.schedule = Schedule()
self.logger = Logger() #throws IOError if file is open
inf = Frame(self)
inf.pack(padx=10,pady=10,side='top')
Label(inf, text="Name:").grid(row=0,column=0,sticky=E,ipady=2,pady=2,padx=10)
Label(inf, text='Date:').grid(row=1,column=0,sticky=E,ipady=2,pady=2,padx=10)
Label(inf, text="Workout:").grid(row=2,column=0,sticky=E,ipady=2,pady=2,padx=10)
self.name_cb = Combobox(inf, textvariable=self.name, width=30,
values=self.names)
self.name_cb.grid(row=0,column=1,sticky=W,columnspan=2)
self.date_ent = Entry(inf, textvariable=self.date)
self.date_ent.grid(row=1,column=1,sticky=W)
self.date_ent.bind('<FocusOut>', self.update_workouts)
Button(inf,text='Edit', command=self.enable_date_ent).grid(row=1,column=2,sticky=E)
self.workout_cb = Combobox(inf, textvariable=self.workout, width=30,
values=self.workouts_form,state='readonly')
self.workout_cb.grid(row=2,column=1,sticky=W,columnspan=2)
self.log_btn=Button(inf,text="Log Workout",command=self.log,width=12)
self.log_btn.grid(row=3,column=1,columnspan=2,pady=4,sticky='ew')
stf = Frame(self)
stf.pack(padx=10,pady=10,fill='x',side='top')
self.scrolled_text = ScrolledText(stf,height=15,width=50,wrap='word',state='disabled')
self.scrolled_text.pack(expand=True,fill='both')
self.update_workouts()
self.update_names()
self.bind('<Return>',self.log)
self.name_cb.focus_set() # set the focus here when created
#disable the date field
self.disable_date_ent()
#start time caller
self.time_caller()
def output_text(self,outstr):
self.scrolled_text['state'] = 'normal'
self.scrolled_text.insert('end',outstr)
self.scrolled_text.see('end')
self.scrolled_text['state'] = 'disabled'
def log(self, e=None):
#check to see if name is blank
logged = False
if self.name.get() == '':
self.output_text("! - Please select your name.\n")
elif self.workout.get() not in self.workouts_form:
self.output_text("! - Select valid workout.\n")
elif self.name.get() not in self.names: # new customer
self.new_customer_error()
else: # log the workout
name = self.name.get().split(' ',2)
(line, r) = self.customers.find(name[2],name[0],name[1])
name_str = str(self.name.get())
date = datetime.strptime(str(self.date.get()),'%m/%d/%Y')
if not line:
self.output_text("!! - No record: " + self.name.get() + ".\n")
while (not logged):
try:
self.logger.log(self.workouts[self.workout_cb.current()][0],
self.workouts[self.workout_cb.current()][1],
name_str, day=date)
logged = True
except IOError:
showerror("Error writting to file", "Please close " + self.logger.filename + " and press OK.")
if logged:
self.output_text(self.name.get() + " - " + line[3] + "\n")
logged_payment = False
while(not logged_payment):
#.........这里部分代码省略.........