本文整理汇总了Python中tkinter.ttk.Entry.focus方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.focus方法的具体用法?Python Entry.focus怎么用?Python Entry.focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Entry
的用法示例。
在下文中一共展示了Entry.focus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemberChecker
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import focus [as 别名]
class MemberChecker(PanedWindow):
def __init__(self, parent):
PanedWindow.__init__(self, parent, background="white")
self.parent = parent
self.init_data()
self.init_log()
self.init_ui()
self.update_status()
def init_data(self):
self.data_store = api.DataStore()
def init_log(self):
self.entrance_log = entrance_log.EntranceLog()
def init_ui(self):
self.parent.title("Member Checker")
self.columnconfigure(3, weight=3)
self.pack(fill=BOTH, expand=True)
self.input = StringVar()
self.input_entry = Entry(self, textvariable=self.input)
self.input_entry.bind('<Return>', self.submit)
self.input_entry.grid(row=0, column=0, columnspan=3, sticky=E + W)
self.result = StringVar()
self.result_label = Label(self, textvariable=self.result)
self.result_label.grid(row=3, column=0, columnspan=3, sticky=E + W)
self.name = StringVar()
name_label = Label(self, textvariable=self.name)
name_label.grid(row=2, column=0, columnspan=3, sticky=E + W)
self.status = StringVar()
status_label = Label(self, textvariable=self.status)
status_label.grid(row=4, column=0, columnspan=4, sticky=E + W)
submit_button = Button(self, text="Submit", command=self.submit)
submit_button.grid(row=1, column=2)
enter_without_card_button = Button(self, text="Enter without card", command=self.enter_without_card)
enter_without_card_button.grid(row=1, column=0)
enter_member_without_card_button = Button(self, text="Enter member without card",
command=self.enter_member_without_card)
enter_member_without_card_button.grid(row=1, column=1)
self.entrance_log_list = Listbox(self)
self.entrance_log_list.grid(row=0, column=3, rowspan=4, sticky=E + W + S + N)
self.input_entry.focus()
def load_data(self):
if messagebox.askyesno("Load new API Data",
"Are you sure you want to load the new API data? All previous data will be removed. The program might be unresponsive for a few seconds, but don't kill it, please! It has feelings too."):
self.data_store.load_api_data()
def enter_by_identification(self, identification):
member = self.data_store.find_member_by_identification(identification)
if member is None:
if messagebox.askyesno("Not a member",
"This university identification is not registered as a member. Do you want to let them in as a non-member?"):
self.enter_non_member_by_identification(identification)
else:
self.enter_member(member)
def enter_by_barcode(self, barcode):
member = self.data_store.find_member_by_barcode(barcode)
if member is None:
if messagebox.askyesno("Not a member",
"This barcode is not registered as a member. Do you want to let them in as a non-member?"):
self.enter_non_member_by_barcode(barcode)
else:
self.enter_member(member)
def enter_non_member_by_identification(self, identification):
self.entrance_log.enter_non_member_by_identification(identification)
self.enter_non_member()
def enter_non_member_by_barcode(self, barcode):
self.entrance_log.enter_non_member_by_barcode(barcode)
self.enter_non_member()
def enter_without_card(self):
self.clear_result()
self.entrance_log.enter_without_card()
self.enter_non_member()
self.input_entry.focus()
def enter_member(self, member):
inside_result = self.entrance_log.is_member_inside(member)
if inside_result[0]:
if not messagebox.askyesno("Already inside",
"This membership card has already been used to enter at {}. Are you sure you want to register it again? Normally you should let this person enter without card (and bill them accordingly).".format(
inside_result[1])):
return
self.entrance_log.enter_member(member)
self.result.set('Member!')
self.result_label.configure(background='green')
#.........这里部分代码省略.........
示例2: _gui
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import focus [as 别名]
def _gui():
try:
from tkinter import Tk, ttk, filedialog, messagebox, StringVar, IntVar
from tkinter.ttk import Button, Entry, Frame, Label, LabelFrame, Notebook, Radiobutton, Style
except:
sys.exit("Unable to load tkinter. Aborting.")
def _check_single(): #check the input and accordingly give the output... for the f_single tab
if txt_f_single_entry.get()=="":
lbl_f_single_result.config(text="", style="TLabel")
elif check_afm(txt_f_single_entry.get()):
lbl_f_single_result.config(text="Έγκυρο ΑΦΜ.", style="valid.TLabel")
else:
lbl_f_single_result.config(text="Άκυρο ΑΦΜ.", style="invalid.TLabel")
def _select_input_file():
strv_f_file_input.set(filedialog.askopenfilename(title="Άνοιγμα αρχείου"))
if strv_f_file_input.get() != "" and strv_f_file_output.get() != "":
btn_f_file_submit.config(state="normal")
else: btn_f_file_submit.config(state="disabled")
#TODO a much better mechanism to enable / disable btn_f_file_submit is needed.
def _select_output_file():
strv_f_file_output.set(filedialog.asksaveasfilename(title="Αποθήκευση ως..."))
if strv_f_file_input.get() != "" and strv_f_file_output.get() != "":
btn_f_file_submit.config(state="normal")
else: btn_f_file_submit.config(state="disabled")
def _check_file():#TODO this could / should be merged with the TUI version...
input_filepath = strv_f_file_input.get()
output_filepath = strv_f_file_output.get()
filter_output = intvar_filter_sel.get()
try:
input_file = open(input_filepath, "r")
output_file = open(output_filepath, "w")
except:
messagebox.showerror(title="Σφάλμα", message="Αδυναμία διαχείρησης των αρχείων που ορίσατε.\n\nΠαρακαλώ επιβεβαιώστε πως το αρχείο με τα δεδομένα υπάρχει, πως έχετε δικαιώματα ανάγνωσης, και πως έχετε δικαιώματα εγγραφής στον κατάλογο εξαγωγής των αποτελεσμάτων.")
return
counter = {True:0, False:0}
for entry in input_file:
validation = check_afm(entry.strip())
counter[validation]+=1
if filter_output == 3 and validation == False:
output_file.write(entry)
elif filter_output == 2 and validation == True:
output_file.write(entry)
elif filter_output == 1:
output_file.write(entry.strip() + "\t" + str(validation) + "\n\r")
lbl_f_file_result.config(text="Σύνολο: "+str(counter[True]+counter[False])+"\nΈγκυρα: "+str(counter[True])+"\nΆκυρα: "+str(counter[False]))
#create the window
main_window = Tk()
main_window.title("Έλεγχος εγκυρότητας Α.Φ.Μ. (v 2.0)")
main_window.geometry("600x180")
main_window.minsize(600,180)
#fool arround with styling
style = ttk.Style()
style.configure("valid.TLabel", background="green")
style.configure("empty.TLabel", background="white")
style.configure("invalid.TLabel", background="red")
style.configure("TNotebook", padding = 10)
#create the Notebook
tabs = Notebook(main_window)
f_single = Frame(tabs)
f_file = Frame(tabs)
tabs.add(f_single, text="Μεμονομένα Α.Φ.Μ.")
tabs.add(f_file, text="Λίστα από αρχείο")#add state="disabled" prior to git push until ready
tabs.pack(anchor="nw")
#add some widgets in f_single tab
lbl_f_single_instructions = Label(f_single, text="Εισάγετε έναν ΑΦΜ για έλεγχο")
lbl_f_single_instructions.grid(column=0, row=0)
lbl_f_single_result = Label(f_single, text="", width=10, justify="center")
lbl_f_single_result.grid(column=1, row=0, rowspan=2, sticky="ewns")
txt_f_single_entry = Entry(f_single, width=11)
txt_f_single_entry.focus()
txt_f_single_entry.bind("<KeyRelease>", lambda e: _check_single() )
txt_f_single_entry.grid(column=0,row=1)
#btn_f_single_submit = Button(f_single, text="Έλεγχος", command=_check_single)
#btn_f_single_submit.grid(column=0,row=2)
#add some widgets in f_file tab
lbl_f_file_finput = Label(f_file, text="Άνοιγμα...")
lbl_f_file_finput.grid(column=0, row=0)
strv_f_file_input = StringVar()
txt_f_file_finput = Entry(f_file, textvariable = strv_f_file_input)
txt_f_file_finput.grid(column=1, row=0)
btn_f_file_finput = Button(f_file, text="...", width=3, command=_select_input_file)
btn_f_file_finput.grid(column=2, row=0, sticky="W")
lbl_f_file_foutput = Label(f_file, text="Αποθήκευση ως...")
lbl_f_file_foutput.grid(column=0, row=1)
strv_f_file_output = StringVar()
txt_f_file_foutput = Entry(f_file, textvariable = strv_f_file_output)
txt_f_file_foutput.grid(column=1, row=1)
btn_f_file_foutput = Button(f_file, text="...", width=3, command=_select_output_file)
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import focus [as 别名]
class SettingsUI:
def __init__(self, mainFrame):
"initiates settings and creates the interface"
self.playerList = []
self.gameList = ("301", "501", "Clock")
self.initUI(mainFrame)
def buildPlayerHeaderString(self):
"""Build a connection string from a dictionary of parameters.
Returns string."""
return "Players: " + ", ".join(["%s" % player.name for player in self.playerList])
def addPlayerText(self, name):
self.playerList.append(Player(name))
#bind add player click event
def onAddPlayerClick(self, event):
"callback method for the add player button"
self.addPlayer()
def onAddPlayerEnter(self, event):
"callback method for the add player button"
if event.keycode == 13:
self.addPlayer()
def addPlayer(self):
name = self.playerNameEntry.get()
if name:
self.addPlayerText(name)
self.playerString.set(self.buildPlayerHeaderString())
self.nameFieldVar.set("")
self.playerNameEntry.focus()
return("break")
def initUI(self, mainFrame):
"""initialize the User Interface"""
# styles
style = Style()
style.configure("GRN.TLabel", background="#ACF059")
style.configure("GRN.TFrame", background="#ACF059")
style.configure("BLK.TFrame", background="#595959")
# create top frame
topFrame = Frame(mainFrame, style="GRN.TFrame", padding=8)
topFrame.pack(fill=BOTH, side=TOP)
# create black border
borderFrame = Frame(mainFrame, style="BLK.TFrame")
borderFrame.pack(fill=BOTH, side=TOP)
# create add player frame
addPlayerFrame = Frame(mainFrame, padding=8)
addPlayerFrame.pack(side=TOP)
# create text field for add button
self.nameFieldVar = StringVar()
self.playerNameEntry = Entry(addPlayerFrame, textvariable = self.nameFieldVar)
self.playerNameEntry.pack(side=LEFT)
# create add player button
addButton = Button(addPlayerFrame, text="Add player")
addButton.pack(side=LEFT)
# create choose game list
self.currentGame = StringVar()
self.currentGame.set(self.gameList[0])
gameDropDown = OptionMenu(mainFrame, self.currentGame, self.gameList[0], *self.gameList)
gameDropDown.pack(side=TOP)
# create start game button
startGameButton = Button(mainFrame, text="Start")
startGameButton.bind("<Button-1>", self.startGame)
startGameButton.pack(side=TOP)
# create label and set text
self.playerString = StringVar()
self.playerString.set(self.buildPlayerHeaderString())
headerLabel = Label(topFrame, textvariable=self.playerString, style="GRN.TLabel")
headerLabel.pack(side=TOP)
addButton.bind("<Button-1>", self.onAddPlayerClick)
self.playerNameEntry.bind("<Key>", self.onAddPlayerEnter)
#set focus
self.playerNameEntry.focus()
def startGame(self,event):
"starts the selected game"
if self.playerList:
mainFrame.pack_forget()
gameFrame = Frame(root)
gameFrame.pack(fill=BOTH, expand=1)
game = self.currentGame.get()
if game == "301":
gameX01.GameX01(gameFrame, self.playerList)
#.........这里部分代码省略.........