本文整理汇总了Python中tkinter.Entry.focus_set方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.focus_set方法的具体用法?Python Entry.focus_set怎么用?Python Entry.focus_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Entry
的用法示例。
在下文中一共展示了Entry.focus_set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Add_Item_Modal
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Add_Item_Modal(Modal):
def __init__(self, parent=None, title="Add Item"):
Modal.__init__(self, parent, title, geometry="580x110" if system() == "Windows" else "485x95")
def initialize(self):
label = Label(self, font=("TkTextFont", 13), text="Item Name: ")
label.grid(row=0, column=0, pady=10)
self.item_name_box = Entry(self, font=("TkTextFont", 13), width=32)
self.item_name_box.grid(row=0, column=1, pady=10, sticky="EW")
self.item_name_box.focus_set()
cancel_button = Button(self, text="Cancel", width=20, command=self.cancel)
self.bind("<Escape>", self.cancel)
cancel_button.grid(row=1, column=0, pady=10, padx=10, sticky="W")
ok_button = Button(self, text="OK", width=20, command=self.ok)
self.bind("<Return>", self.ok)
ok_button.grid(row=1, column=1, pady=10, padx= 5, sticky="E")
def ok(self, event=None):
name = self.item_name_box.get()
if name != "":
self.item_name = self.item_name_box.get()
self.destroy()
def cancel(self, event=None):
self.item_name = None
self.destroy()
def show(self):
Modal.show(self)
return self.item_name
示例2: Edit_Ingredient_Modal
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Edit_Ingredient_Modal(Modal):
def __init__(self, parent=None, title="Add Ingredient"):
Modal.__init__(self, parent, title, geometry="520x100" if system() == "Windows" else "565x95")
def initialize(self):
short_label = Label(self, text="Short Name")
short_label.grid(row=0, column=0, sticky="W", padx=5)
self.new_short_box = Entry(self, width=10)
self.new_short_box.focus_set()
self.new_short_box.grid(row=1, column=0, sticky="W", padx=5)
item_label = Label(self, text="Item Name")
item_label.grid(row=0, column=1)
self.new_item_box = Entry(self, width=40)
self.new_item_box.grid(row=1, column=1, sticky="EW")
amount_label = Label(self, text="Amount")
amount_label.grid(row=0, column=2, sticky="EW")
self.new_amount_box = Entry(self, width=5)
self.new_amount_box.grid(row=1, column=2, padx=10, sticky="EW")
cancel_button = Button(self, text="Cancel", width=10, command=self.cancel)
self.bind("<Escape>", self.cancel)
cancel_button.grid(row=3, column=0, pady=10, padx=5, sticky="W")
ok_button = Button(self, text="OK", width=10, command=self.ok)
self.bind("<Return>", self.ok)
ok_button.grid(row=3, column=2, pady=10, sticky="E")
self.bind("<Return>", self.ok)
self.bind("<Escape>", self.cancel)
def ok(self, event=None):
new_short = self.new_short_box.get()
new_name = self.new_item_box.get()
new_amount = self.new_amount_box.get()
if new_short is not None and new_name is not None and new_amount is not None and new_amount.isdigit():
if new_name != "" and new_amount != "":
self.new_short_name = new_short
self.new_item_name = new_name
self.new_amount = int(new_amount)
self.destroy()
def cancel(self, event=None):
self.new_short_name = None
self.new_item_name = None
self.new_amount = None
self.destroy()
def show(self, current_short_name, current_name, current_amount):
self.new_short_box.insert(0, current_short_name)
self.new_item_box.insert(0, current_name)
self.new_amount_box.insert(0, current_amount)
Modal.show(self)
return (self.new_short_name, self.new_item_name, self.new_amount)
示例3: Add_Mod_Modal
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Add_Mod_Modal(Modal):
def __init__(self, parent=None, title="Add Mod"):
Modal.__init__(self, parent, title, geometry="675x150" if system() == "Windows" else "525x135")
def initialize(self):
short_name_label = Label(self, font=("TkTextFont", 13), text="Short Name: ")
short_name_label.grid(row=0, column=0, pady=10, padx=10)
self.short_name_box = Entry(self, font=("TkTextFont", 13), width=15)
self.short_name_box.focus_set()
self.short_name_box.grid(row=0, column=1, pady=10)
long_name_label = Label(self, font=("TkTextFont", 13), text="Long Name: ")
long_name_label.grid(row=1, column=0, pady=5, padx=10)
self.long_name_box = Entry(self, font=("TkTextFont", 13), width=35)
self.long_name_box.grid(row=1, column=1, pady=5)
cancel_button = Button(self, text="Cancel", width=10, command=self.cancel)
self.bind("<Escape>", self.cancel)
cancel_button.grid(row=2, column=0, pady=10, padx=5, sticky="W")
open_button = Button(self, text="Open...", width=10, command=self.open)
open_button.grid(row=2, column=1, pady=10)
ok_button = Button(self, text="OK", width=10, command=self.ok)
self.bind("<Return>", self.ok)
ok_button.grid(row=2, column=2, pady=10, sticky="E")
def ok(self, event=None):
sn = self.short_name_box.get()
ln = self.long_name_box.get()
if sn != "" and ln != "":
self.short_name = sn
self.long_name = ln
self.destroy()
def open(self, event=None):
self.short_name = "open"
self.long_name = "open"
self.destroy()
def cancel(self, event=None):
self.short_name = None
self.long_name = None
self.destroy()
def show(self):
Modal.show(self)
return (self.short_name, self.long_name)
示例4: ConcordanceSearchView
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
#.........这里部分代码省略.........
def _bind_event_handlers(self):
self.top.bind(CORPUS_LOADED_EVENT, self.handle_corpus_loaded)
self.top.bind(SEARCH_TERMINATED_EVENT, self.handle_search_terminated)
self.top.bind(SEARCH_ERROR_EVENT, self.handle_search_error)
self.top.bind(ERROR_LOADING_CORPUS_EVENT, self.handle_error_loading_corpus)
def _poll(self):
try:
event = self.queue.get(block=False)
except q.Empty:
pass
else:
if event == CORPUS_LOADED_EVENT:
self.handle_corpus_loaded(event)
elif event == SEARCH_TERMINATED_EVENT:
self.handle_search_terminated(event)
elif event == SEARCH_ERROR_EVENT:
self.handle_search_error(event)
elif event == ERROR_LOADING_CORPUS_EVENT:
self.handle_error_loading_corpus(event)
self.after = self.top.after(POLL_INTERVAL, self._poll)
def handle_error_loading_corpus(self, event):
self.status['text'] = 'Error in loading ' + self.var.get()
self.unfreeze_editable()
self.clear_all()
self.freeze_editable()
def handle_corpus_loaded(self, event):
self.status['text'] = self.var.get() + ' is loaded'
self.unfreeze_editable()
self.clear_all()
self.query_box.focus_set()
def handle_search_terminated(self, event):
#todo: refactor the model such that it is less state sensitive
results = self.model.get_results()
self.write_results(results)
self.status['text'] = ''
if len(results) == 0:
self.status['text'] = 'No results found for ' + self.model.query
else:
self.current_page = self.model.last_requested_page
self.unfreeze_editable()
self.results_box.xview_moveto(self._FRACTION_LEFT_TEXT)
def handle_search_error(self, event):
self.status['text'] = 'Error in query ' + self.model.query
self.unfreeze_editable()
def corpus_selected(self, *args):
new_selection = self.var.get()
self.load_corpus(new_selection)
def load_corpus(self, selection):
if self.model.selected_corpus != selection:
self.status['text'] = 'Loading ' + selection + '...'
self.freeze_editable()
self.model.load_corpus(selection)
def search(self):
self.current_page = 0
self.clear_results_box()
self.model.reset_results()
query = self.query_box.get()
示例5: Example
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("")
#self.style = Style()
#self.style.theme_use("clam")
#self.pack(fill=BOTH, expand = 1)
self.labelU = Label(self, text="U:")
self.labelP = Label(self, text="P:")
self.mailrecipient = 'GoldenSights'
self.entryUsername = Entry(self)
self.entryUsername.focus_set()
self.entryUsername.bind('<Return>', lambda event: self.entryPassword.focus_set())
self.entryPassword = Entry(self)
self.entryPassword.config(show='•')
self.entryPassword.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton = Button(self, text="Login", command= lambda: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.config(width=6)
self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
self.quitbutton.config(width=6)
self.labelU.grid(row=0, column=0,padx=0)
self.entryUsername.grid(row=0, column=1)
self.labelP.grid(row=1, column=0)
self.entryPassword.grid(row=1, column=1, pady=4)
self.newbutton.grid(row=2, column=1)
self.quitbutton.grid(row=3, column=1, pady=4)
self.labelErrorPointer = Label(self, text="◀")
self.indicatorGreen = PhotoImage(file="indicatorGreen.gif")
self.indicatorRed = PhotoImage(file="indicatorRed.gif")
self.indicatorBlue = PhotoImage(file="indicatorBlue.gif")
self.indicatorBlack = PhotoImage(file="indicatorBlack.gif")
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
w=400
h=480
x = (sw - w) / 2
y = (sh - h) / 2
self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y-50))
def login(self, username, password):
print('U: ' + username)
self.username = username
if username == '' or not all(char in string.ascii_letters+string.digits+'_-' for char in username):
print('Please enter a username')
self.entryUsername.focus_set()
self.labelErrorPointer.grid(row=0, column=2)
elif password == '':
print('Please enter a password')
self.entryPassword.focus_set()
self.labelErrorPointer.grid(row=1, column=2)
else:
self.labelErrorPointer.grid_forget()
print('Attempting login for ' + username)
try:
self.USERAGENT = username + ' practices Tkinter+PRAW mixing with utility by /u/GoldenSights.'
self.r = praw.Reddit(self.USERAGENT)
#self.r.login(username, password)
print('Success')
self.labelU.grid_forget()
self.labelP.grid_forget()
self.entryUsername.grid_forget()
self.entryPassword.grid_forget()
self.newbutton.grid_forget()
self.quitbutton.grid_forget()
self.usernamelabel = Label(self, text=username + ', Sending to /u/' + self.mailrecipient)
self.usernamelabel.grid(row=0, column=0, columnspan=8)
self.quitbutton.grid(row=900, column=0)
self.labellist = []
self.entrylist = []
self.verifylist = []
self.misclist = []
self.optionDiscuss = "Discussion Flair + Crossposting"
self.optionRegister = "Register a new Candidate"
self.prevmode = self.optionDiscuss
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
#.........这里部分代码省略.........
text="Statistics by type",
variable=self.box,
value="Statistics by type",
command=self.refresh_results_window,
)
msgCat = Radiobutton(
radio_frame,
text="Messages by category",
variable=self.box,
value="Messages by category",
command=self.refresh_results_window,
)
msg = Radiobutton(
radio_frame, text="Messages", variable=self.box, value="Messages", command=self.refresh_results_window
)
report.select()
report.grid(column=0, row=0, sticky=W)
rawMet.grid(column=1, row=0, sticky=W)
dup.grid(column=2, row=0, sticky=W)
msg.grid(column=3, row=0, sticky=E)
stat.grid(column=0, row=1, sticky=W)
msgCat.grid(column=1, row=1, sticky=W)
ext.grid(column=2, row=1, columnspan=2, sticky=W)
# dictionary for check boxes and associated error term
self.msg_type_dict = {
"I": lambda: self.information_box.get() == 1,
"C": lambda: self.convention_box.get() == 1,
"R": lambda: self.refactor_box.get() == 1,
"E": lambda: self.error_box.get() == 1,
"W": lambda: self.warning_box.get() == 1,
"F": lambda: self.fatal_box.get() == 1,
}
self.txtModule.focus_set()
def select_recent_file(self, event):
"""adds the selected file in the history listbox to the Module box"""
if not self.showhistory.size():
return
selected = self.showhistory.curselection()
item = self.showhistory.get(selected)
# update module
self.txtModule.delete(0, END)
self.txtModule.insert(0, item)
def refresh_msg_window(self):
"""refresh the message window with current output"""
# clear the window
self.lbMessages.delete(0, END)
for msg in self.msgs:
if self.msg_type_dict.get(msg[0])():
msg_str = self.convert_to_string(msg)
self.lbMessages.insert(END, msg_str)
fg_color = COLORS.get(msg_str[:3], "black")
self.lbMessages.itemconfigure(END, fg=fg_color)
def refresh_results_window(self):
"""refresh the results window with current output"""
# clear the window
self.results.delete(0, END)
try:
for res in self.tabs[self.box.get()]:
self.results.insert(END, res)
except:
pass
示例7: Tk
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
window = Tk() # cria uma janela
window.title('Youtube Downloader') # seta o título da janela
window.geometry('500x200') # seta o tamanho da janela
window.resizable(0,0) # não permite redimensionamento da janela
# label do título do programa
title = Label(window, text='Youtube Downloader', font=('Arial', 25), fg='Blue')
title.pack()
# label da mensagem de execução do programa
msg = Label(window, text='', font=('Arial', 15))
entry_url = Entry(window, width=60, justify='center') # cria uma entrada de texto
entry_url.insert(0, 'Cole aqui a URL') # seta o texto
entry_url.pack() # gerenciador de geometria
entry_url.focus_set() # obtém o foco para a entrada de texto
entry_name_video = Entry(window, width=60, justify='center')
entry_name_video.insert(0, 'Digite um nome para o vídeo')
entry_name_video.pack()
# função para o evento de clique do botão
def click_button():
# obtém os textos
url = entry_url.get()
name_video = entry_name_video.get()
# se a função retornar 'True'
if download_video(url, name_video):
msg['fg'] = 'Green'
开发者ID:michel-rodrigues,项目名称:intro-python-flisol-2016,代码行数:33,代码来源:youtube-downloader-gui_gabarito.py
示例8: Example
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("")
self.style = Style()
self.style.theme_use("clam")
self.pack(fill=BOTH, expand = 1)
self.labelU = Label(self, text="U:")
self.labelP = Label(self, text="P:")
self.entryUsername = Entry(self)
self.entryUsername.config(relief='flat')
self.entryUsername.focus_set()
self.entryUsername.bind('<Return>', lambda event: self.entryPassword.focus_set())
self.entryPassword = Entry(self)
self.entryPassword.config(relief='flat', show='•')
self.entryPassword.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton = Button(self, text="Login", command= lambda: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.config(width=6)
self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
self.quitbutton.config(width=6)
self.mailIconRed = PhotoImage(file="mail.gif")
self.labelRed = Label(self, image=self.mailIconRed)
self.mailIconGray = PhotoImage(file="mail2.gif")
self.labelGray = Label(self, image=self.mailIconGray)
self.labelKarma = Label(self, text = '•')
self.labelU.grid(row=0, column=0)
self.entryUsername.grid(row=0, column=1)
self.labelP.grid(row=1, column=0)
self.entryPassword.grid(row=1, column=1, pady=4)
self.newbutton.grid(row=2, column=1)
self.quitbutton.grid(row=3, column=1, pady=4)
'''
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
w=150
h=112
x = (sw - w) / 2
y = (sh - h) / 2
self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y-50))
'''
def login(self, username, password):
#print('U: ' + username)
self.username = username
if username == '':
#print('Please enter a username')
self.entryUsername.focus_set()
elif password == '':
#print('Please enter a password')
self.entryPassword.set_focus()
if username != '' and password != '':
#print('Attempting login for ' + username)
try:
self.USERAGENT = username + ' scans his inbox for new mail.'
self.r = praw.Reddit(self.USERAGENT)
#self.r.config._ssl_url = None
self.r.login(username, password)
#print('You have logged in as ' + username)
self.labelU.grid_forget()
self.labelP.grid_forget()
self.entryUsername.grid_forget()
self.entryPassword.grid_forget()
self.newbutton.grid_forget()
self.quitbutton.grid_forget()
self.usernamelabel = Label(self, text=username)
self.usernamelabel.grid(row=0, column=0, pady = 10, padx = 30)
self.quitbutton.grid(row=1, column=0)
self.labelKarma.grid(row = 3, column = 0)
self.playedSound = 'false'
self.loop()
except praw.errors.InvalidUserPass:
pass
#print('Invalid username or password')
def loop(self):
while True:
try:
#print('Starting new search')
hasmail = 'false'
for msg in self.r.get_unread(limit=None):
hasmail = 'true'
#.........这里部分代码省略.........
示例9: Example
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus_set [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.username = ''
self.r = praw.Reddit(USERAGENT)
self.parent.title("")
self.style = Style()
self.style.theme_use("clam")
self.pack(fill=BOTH, expand = 1)
self.labelU = Label(self, text="U:")
self.labelP = Label(self, text="P:")
self.entryUsername = Entry(self)
self.entryUsername.config(relief='flat')
self.entryUsername.focus_set()
self.entryUsername.bind('<Return>', lambda event: self.login(self.entryUsername.get()))
self.entryUsername.bind('<Up>', lambda event: self.entryUsername.insert(0, self.username))
self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
self.quitbutton.config(width=6)
self.labelKarma = Label(self, text = '•')
self.labelKarma.grid(row = 3, column = 1)
self.labelU.grid(row=0, column=0)
self.entryUsername.grid(row=0, column=1)
self.quitbutton.grid(row=2, column=1, pady=4)
self.usernamelabel = Label(self, text='')
self.usernamelabel.grid(row=1, column=1)
def login(self, username):
print('U: ' + username)
self.username = username
self.entryUsername.delete(0, 200)
if username == '':
self.entryUsername.focus_set()
else:
try:
self.user = self.r.get_redditor(self.username)
lkarma = str(self.user.link_karma)
ckarma = str(self.user.comment_karma)
lkarma = self.karmaRound(lkarma)
ckarma = self.karmaRound(ckarma)
karmastring = lkarma + ' • ' + ckarma
self.labelKarma.config(text = karmastring)
self.usernamelabel.config(text= self.username)
except:
self.labelKarma.config(text = '•')
self.usernamelabel.config(text= 'User not found')
pass
def karmaRound(self, karma):
if len(karma) > 4 and len(karma) < 7:
tstring = karma[:-3]
tstring2 = karma[-3:]
karma = tstring + '.' + tstring2[:2] + 'K'
return karma
if len(karma) > 6:
tstring = karma[:-6]
tstring2 = karma[-6:]
karma = tstring + '.' + tstring2[:2] + 'M'
return karma
else:
return karma