本文整理汇总了Python中tkinter.Entry.focus方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.focus方法的具体用法?Python Entry.focus怎么用?Python Entry.focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Entry
的用法示例。
在下文中一共展示了Entry.focus方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CircleBuilderPopup
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class CircleBuilderPopup(BuilderPopup):
"""
Class that launches a popup and collects user data to pass data back to the main window
to build a circle.
"""
def __init__(self, master):
"""
Establish the GUI of this popup
"""
BuilderPopup.__init__(self, master)
self.data = (0, 0)
self.radius = Label(self.top, text="Radius")
self.radius_entry = Entry(self.top, width=self.width, bd=self.bd)
self.center = Label(self.top, text="Center")
self.center_entry = Entry(self.top, width=self.width, bd=self.bd)
self.build_circle_submit = Button(self.top, text="Build!", command=self.cleanup)
self.top.bind("<Return>", self.cleanup)
self.radius.grid(row=0, column=0)
self.radius_entry.grid(row=0, column=1)
self.center.grid(row=1, column=0)
self.center_entry.grid(row=1, column=1)
self.build_circle_submit.grid(row=2, column=0, columnspan=2)
self.top_left = 0
self.bottom_right = 0
self.radius_entry.focus()
def cleanup(self, entry=None):
"""
Collect the data from the user and package it into object variables, then close.
"""
center = complex(0, 0)
if self.center_entry.get():
center = complex(allow_constants(self.center_entry.get()))
self.data = (float(allow_constants(self.radius_entry.get())), center)
self.top.destroy()
示例2: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def __init__(self):
root = Tk()
root.title("Calculator")
self.string = StringVar()
txtDisplay = Entry(root,textvariable = self.string,insertwidth = 1 , font = "Helvetica 17 bold")
txtDisplay.grid(row = 0,column = 0,columnspan = 6)
txtDisplay.focus()
values = ["7","8","9","/","Clear",
"4","5","6","*","<-",
"1","2","3","-","=",
"0",".","%","+"]
i = 0
row = 1
col = 0
for txt in values:
if(i==5):
row = 2
col = 0
if(i==10):
row = 3
col = 0
if(i==15):
row = 4
col = 0
padx = 23
pady = 23
if(txt == "="):
btn = Button(root,height = 2,width = 4,padx = padx,pady =pady,text = txt,
command = lambda:self.equals())
btn.grid(row = row,column = col,columnspan = 2,rowspan = 2,padx = 1,pady =1)
elif(txt == "<-"):
btn = Button(root,height = 2,width = 4,padx = 10,pady = 10,text = txt,
command = lambda:self.DeleteText())
btn.grid(row = row,column = col,columnspan = 2,rowspan = 1,padx = 1,pady =1)
elif(txt == "Clear"):
btn = Button(root,height = 2,width = 4,padx = 10,pady = 10,text = txt,
command = lambda:self.ClearText())
btn.grid(row = row,column = col,columnspan = 2,rowspan = 1,padx = 1,pady =1)
else:
btn = Button (root,height = 2,width = 4,padx = 10,pady = 10,text = txt,
command = lambda txt=txt:self.addchar(txt))
btn.grid(row = row,column = col,padx = 1,pady =1)
col = col + 1
i = i + 1
root.mainloop()
示例3: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def __init__(self):
window = Tk()
window.title("Calculator")
self.string = StringVar()
entry = Entry(window, textvariable=self.string)
entry.grid(row=0, column=0, columnspan=6)
entry.focus()
values= ["7", "8", "9", "/", "Clear", "<-",
"4", "5", "6", "*", "(", ")", "1",
"2", "3", "-", "=", "0", ".", "%", "+"]
i=0
row=1
col=0
for txt in values:
padx=10
pady=10
if(i==6):
row=2
col=0
if(i==12):
row=3
col=0
if(i==17):
col=0
row=4
if(txt=="="):
btn = Button(window, height=2, width=4, padx=23, pady=23, text=txt,
command=lambda txt=txt:self.equals())
btn.grid(row=row, column=col, columnspan=2, rowspan=2, padx=1, pady=1)
elif(txt=="Clear"):
btn = Button(window, height=2, width=4, padx=padx, pady=pady, text=txt,
command=lambda txt=txt:self.clearTxt())
btn.grid(row=row, column=col, padx=1, pady=1)
elif(txt=="<-"):
btn = Button(window, height=2, width=4, padx=padx, pady=pady, text=txt,
command=lambda txt=txt:self.delete())
btn.grid(row=row, column=col, padx=1, pady=1)
else:
btn = Button(window, height=2, width=4, padx=padx, pady=pady, text=txt,
command=lambda txt=txt:self.addChar(txt))
btn.grid(row=row, column=col, padx=1, pady=1)
col=col+1
i=i+1
window.mainloop()
示例4: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class AddRestrictionDialog:
def __init__(self, parent):
self.parent = parent
self.gui = Toplevel(parent.guiRoot)
self.gui.grab_set()
self.gui.focus()
self.gui.columnconfigure(0, weight=1)
self.gui.columnconfigure(1, weight=1)
Label(self.gui, text="Enzyme:").grid(row=0, column=0, sticky="e", padx=5)
self.entryEnzyme = Entry(self.gui)
self.entryEnzyme.grid(row=0, column=1, sticky="w", padx=5, pady=10)
self.frameButtonGroup = Frame(self.gui)
self.frameButtonGroup.grid(row=1, column=0, columnspan=2, pady=10)
self.buttonOK = Button(self.frameButtonGroup, text=" OK ")
self.buttonCancel = Button(self.frameButtonGroup, text=" Cancel ")
self.buttonOK.grid(row=0, column=1, sticky="w", padx=5)
self.buttonCancel.grid(row=0, column=0, sticky="e", padx=5)
# Set (minimum + max) Window size
self.gui.update()
self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())
self.entryEnzyme.focus()
self.buttonOK.bind("<ButtonRelease>", self.actionOK)
self.buttonCancel.bind("<ButtonRelease>", self.actionCancel)
self.entryEnzyme.bind("<Return>", self.actionOK)
self.gui.mainloop()
# self.gui.grab_release()
# self.gui.destroy()
def actionOK(self, event):
enzymeString = self.entryEnzyme.get()
if enzymeString in rest_dict.keys():
if enzymeString in self.parent.optimizer.restrictionEnzymeList:
showinfo("", (enzymeString + " was already added to the list"))
return
self.parent.optimizer.restrictionEnzymeList.append(enzymeString)
self.parent.guiRoot.event_generate("<<Update>>", when="tail")
self.gui.destroy()
else:
showinfo("", (enzymeString + " is not a valid restriction enzyme"))
def actionCancel(self, event):
self.gui.destroy()
示例5: SpindleBuilderPopup
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class SpindleBuilderPopup(BuilderPopup):
"""
Class that launches a popup and collects user data to pass data back to the main window
to build a circle.
"""
def __init__(self, master):
"""
Establish the GUI of this popup
"""
BuilderPopup.__init__(self, master)
self.data = (0, 0, 0)
self.radius = Label(self.top, text="Radius")
self.radius_entry = Entry(self.top, width=self.width, bd=self.bd)
self.n_circles_entry = Entry(self.top, width=self.width, bd=self.bd)
self.n_circles_label = Label(self.top, text="Number of circles")
self.center = Label(self.top, text="Center")
self.center_entry = Entry(self.top, width=self.width, bd=self.bd)
self.spindles = Label(self.top, text="Number of \"Roots\"")
self.spindles_entry = Entry(self.top, width=self.width, bd=self.bd)
self.build_spindle_submit = Button(self.top, text="Build!", command=self.cleanup)
self.top.bind("<Return>", self.cleanup)
self.radius.grid(row=0, column=0)
self.radius_entry.grid(row=0, column=1)
self.n_circles_label.grid(row=1, column=0)
self.n_circles_entry.grid(row=1, column=1)
self.center.grid(row=2, column=0)
self.center_entry.grid(row=2, column=1)
self.spindles_entry.grid(row=3, column=1)
self.spindles.grid(row=3, column=0)
self.build_spindle_submit.grid(row=4, column=0, columnspan=2)
self.top_left = 0
self.bottom_right = 0
self.radius_entry.focus()
def cleanup(self, entry=None):
"""
Collect the data from the user and package it into object variables, then close.
"""
center = complex(0, 0)
try:
if self.center_entry.get():
#only ingest the center if it is passed by the user
center = complex(allow_constants(self.center_entry.get()))
n_circles = int(self.n_circles_entry.get())
#this is the data that the passed builder function requires
self.data = (int(self.spindles_entry.get()),
float(allow_constants(self.radius_entry.get())), n_circles, center)
except Exception:
#Invalid entry data... eventually log this
pass
self.top.destroy()
示例6: ZoomWindow
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class ZoomWindow(object):
"""description of class"""
def __init__(self, master):
self.top = Toplevel(master)
self.entry_width = 15
self.set_none_limits()
self.real_max_label = Label(self.top, text="Real Max: ")
self.real_min_label = Label(self.top, text="Real Min: ")
self.imag_max_label = Label(self.top, text="Imag Max: ")
self.imag_min_label = Label(self.top, text="Imag Min: ")
self.real_max_entry = Entry(self.top, width=self.entry_width)
self.real_min_entry = Entry(self.top, width=self.entry_width)
self.imag_max_entry = Entry(self.top, width=self.entry_width)
self.imag_min_entry = Entry(self.top, width=self.entry_width)
self.submit_button = Button(self.top, text="Submit", command=self.submit)
self.cancel_button = Button(self.top, text="Cancel", command=self.top.destroy)
self.real_max_label.grid(row=0, column=0)
self.real_min_label.grid(row=1, column=0)
self.imag_max_label.grid(row=2, column=0)
self.imag_min_label.grid(row=3, column=0)
self.real_max_entry.grid(row=0, column=1)
self.real_min_entry.grid(row=1, column=1)
self.imag_max_entry.grid(row=2, column=1)
self.imag_min_entry.grid(row=3, column=1)
self.submit_button.grid(row=4, column=0)
self.cancel_button.grid(row=4, column=1)
self.top.bind("<Return>", self.submit)
self.top.bind("<Escape>", self.top.destroy)
self.real_max_entry.focus()
def set_none_limits(self):
self.imag_min, self.imag_max, self.real_max, self.real_min = (None, None, None, None)
def submit(self, event=None):
try:
self.imag_min = float(self.imag_min_entry.get())
self.imag_max = float(self.imag_max_entry.get())
self.real_min = float(self.real_min_entry.get())
self.real_max = float(self.real_max_entry.get())
if self.imag_min > self.imag_max or self.real_min > self.real_max:
self.set_none_limits()
print("A min field exceeds a max field")
except TypeError:
print("Values passed are not real numbers")
self.top.destroy()
示例7: GridBuilderPopup
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class GridBuilderPopup(BuilderPopup):
"""
Class that launches a popup and collects user data to pass data back to the main window
to build a grid.
"""
def __init__(self, master):
"""
Establish the GUI of this popup
"""
BuilderPopup.__init__(self, master)
self.top_left = complex(0, 0)
self.bottom_right = complex(0, 0)
self.lines = 0
self.top_left_label = Label(self.top, text="\"Top Left\"")
self.top_left_entry = Entry(self.top, width=self.width, bd=self.bd)
self.bottom_right_label = Label(self.top, text="\"Bottom Right\"")
self.bottom_right_entry = Entry(self.top, width=self.width, bd=self.bd)
self.resolution_label = Label(self.top, text="Lines")
self.resolution_entry = Entry(self.top, width=5)
self.build_grid_submit = Button(self.top, text="Build!", command=self.cleanup)
self.top.bind("<Return>", self.cleanup)
self.top_left_label.grid(row=0, column=0)
self.top_left_entry.grid(row=0, column=1)
self.bottom_right_label.grid(row=1, column=0)
self.bottom_right_entry.grid(row=1, column=1)
self.resolution_label.grid(row=2, column=0)
self.resolution_entry.grid(row=2, column=1)
self.build_grid_submit.grid(row=3, column=0, columnspan=2)
self.top_left_entry.focus()
self.data = (0, 0, 0)
def cleanup(self, entry=None):
"""
Collect the data from the user and package it into object variables, then close.
"""
if self.resolution_entry.get().isnumeric():
self.lines = int(self.resolution_entry.get())
self.top_left = complex(allow_constants(self.top_left_entry.get()))
self.bottom_right = complex(allow_constants(self.bottom_right_entry.get()))
#If these conditions are true then we do not have a grid
if (self.top_left.real > self.bottom_right.real
or self.bottom_right.imag > self.top_left.imag or self.lines == 0):
self.bottom_right = self.top_left = complex(0, 0)
self.lines = 0
self.data = (self.top_left, self.bottom_right, self.lines)
self.top.destroy()
示例8: download_track
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def download_track():
def callback(*args):
global notes
if len(track_id.get()):
r = session["session"].get(session["url"]+"download/"+track_id.get())
notes = json.loads(r.text)
root.destroy()
root = Tk()
root.title("Download")
root.geometry("300x90")
track_id = Entry(root, bd = 5, width=20)
track_id.focus()
track_id.pack()
button = Tk_button(root, text="Download", width=30, command=callback)
button.pack()
root.bind("<Return>", callback)
root.mainloop()
示例9: check_login
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def check_login():
def callback(*args):
if login(user.get(), password.get()) == 0:
session["auth"] = 1
session["username"] = user.get()
root.destroy()
root = Tk()
root.title("Log In")
root.geometry("300x90")
user = Entry(root, bd = 5, width=40)
user.focus()
user.pack()
password = Entry(root, bd = 5, show="*", width=40)
password.pack()
button = Tk_button(root, text="Log In", width=30, command=callback)
button.pack()
root.bind("<Return>", callback)
root.mainloop()
示例10: upload_track
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def upload_track():
def callback(*args):
r = session["session"].get(session["url"]+"upload")
i = r.text.find("csrfmiddlewaretoken")
session["csrfmiddlewaretoken"] = r.text[i+28:i+28+32] #Грязные хаки
data = json.dumps(notes)#.encode()
files = {"source": ("{}_{}.json".format(session["username"], track_name.get()), data, 'application/octet-stream', {'Expires': '0'})}
r = session["session"].post(session["url"]+"upload", files=files, data={"csrfmiddlewaretoken": session["csrfmiddlewaretoken"]})
root.destroy()
root = Tk()
root.title("Upload")
root.geometry("300x90")
track_name = Entry(root, bd = 5, width=40)
track_name.focus()
track_name.pack()
button = Tk_button(root, text="Upload", width=30, command=callback)
button.pack()
root.bind("<Return>", callback)
root.mainloop()
示例11: TextSelect
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
class TextSelect(Frame):
def __init__(self, client, anchor, items, destroyAnchor=False):
"""
Args:
client: [SelectionClient] The window that text is returned to.
anchor: A window that the text selection popup is created
relative to.
items: [str], items to display in the listbox.
destroyAnchor: [bool] if true, destroy the anchor after
positioning the window.
"""
self.top = Toplevel()
self.anchor = anchor
self.top.overrideredirect(1)
self.top.wm_geometry('+%s+%s' % (anchor.winfo_rootx() + anchor.winfo_x(),
anchor.winfo_rooty() + anchor.winfo_y()
)
)
super(TextSelect, self).__init__(self.top)
self.entry = Entry(self)
self.client = client
self.items = items
self.place(x = 0.5, y = 0.5, height = 100, width = 100)
self.entry.bind('<Return>', self.close)
self.entry.bind('<KeyPress>', self.filter)
self.entry.bind('<Escape>', self.abort)
self.entry.bind('<Up>', self.up)
self.entry.bind('<Down>', self.down)
self.entry.pack()
# Create the list of items.
self.list = Listbox(self)
for item in self.items:
self.list.insert('end', item)
self.list.pack()
self.grid()
self.entry.focus()
# Reposition the select button against the anchor. We defer this
# until after idle so that the anchor has a chance to get rendered.
def reposition(*args):
self.top.wm_geometry('+%s+%s' % (
anchor.winfo_rootx(),
anchor.winfo_rooty())
)
if destroyAnchor:
anchor.destroy()
self.after_idle(reposition)
def close(self, event):
sel = self.list.curselection()
if sel:
item = self.list.get(sel[0])
else:
item = self.entry.get()
# Note that the order of this appears to be significant: destroying
# before selecting leaves the focus in a weird state.
self.client.selected(item)
self.top.destroy()
return 'braek'
def abort(self, event):
self.top.destroy()
self.client.aborted()
return 'break'
def up(self, event):
sel = self.list.curselection()
if not sel:
self.list.selection_set(0)
return 'break'
sel = sel[0]
print('sel is %s size is %s' % (sel, self.list.size()))
if sel > 0:
print('setting selection to %s' % sel)
self.list.selection_clear(sel)
self.list.selection_set(sel - 1)
self.list.see(sel)
return 'break'
def down(self, event):
sel = self.list.curselection()
if not sel:
self.list.selection_set(0)
return 'break'
sel = sel[0]
print('sel is %s size is %s' % (sel, self.list.size()))
if sel < self.list.size() - 1:
print('setting selection to %s' % (sel + 1))
self.list.selection_clear(sel)
self.list.selection_set(sel + 1)
self.list.see(sel)
return 'break'
def filter(self, event):
"""Filter the listbox based on the contents of the entryfield."""
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import focus [as 别名]
def __init__(self) :
Game.__init__(self)
import socket
import tkinter
self.local = self.host=socket.gethostbyname(socket.gethostname()) # Get local machine ip
from tkinter import Tk,PanedWindow,StringVar,Entry,Button,VERTICAL,HORIZONTAL,Label
fenetre=Tk()
fenetre.title('Socket parameters')
self.netgame_win = PanedWindow(fenetre, orient=VERTICAL)
host_zone=PanedWindow(self.netgame_win, orient=HORIZONTAL)
host=StringVar()
host.set(self.local)
def modifHost(*args) :
self.host=host.get()
if self.local==self.host :
start_button.config(text="Create")
else :
start_button.config(text="Join")
host.trace("w", modifHost)
host_wid=Entry(host_zone, width=30,textvariable=host)
host_wid.pack()
host_label=Label(fenetre, text="Host (you are "+self.local+") :")
host_zone.add(host_label)
host_zone.add(host_wid)
self.netgame_win.add(host_zone)
port_zone=PanedWindow(self.netgame_win, orient=HORIZONTAL)
port=StringVar()
self.port=52333
port.set(str(self.port))
# adress_wid=Label(None, textvariable=self.cost, background='red',width=5, anchor=W)
def modifPort(*args) :
#print "modify port to",port.get()
try :
self.port=int(port.get())
except :
port.set("")
port.trace("w", modifPort)
port_wid=Entry(fenetre, width=30,textvariable=port)
#port_wid.grid(column=0, row=1)
host_wid.focus()
port_wid.pack()
port_label=Label(fenetre, text="Port :")
port_zone.add(port_label)
port_zone.add(port_wid)
self.netgame_win.add(port_zone)
#Create the open button
def start() :
fenetre.destroy()
start_button=Button(self.netgame_win,text="Create",command=start)
self.netgame_win.add(start_button)
self.netgame_win.pack()
#fenetre.focus_set()
#start_button.focus()
fenetre.mainloop()
# Import socket module
self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Reserve a port for your service.
if self.local==self.host :
self.soc.bind((self.host, self.port)) # Bind to the port
print( "socket listening")
self.soc.listen(5) # Now wait for client connection.
self.soc, addr = self.soc.accept() # Establish connection with client.
print( 'Got connection from', addr)
#self.soc.send('Thank you for connecting')
#c.close() # Close the connection
self.firstplayer=choice([1,2])
print( "FIRST PLAYER IS",self.firstplayer)
self.soc.send(str(3-self.firstplayer).encode('utf-8'))
else :
self.soc.connect((self.host, self.port))
print( "connect ok")
p=self.soc.recv(1024).decode('utf-8')
try :
self.firstplayer=int(p)
except :
print( "error concerning first player, got ",p)
self.remains=""