本文整理汇总了Python中tkinter.ttk.Entry.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.insert方法的具体用法?Python Entry.insert怎么用?Python Entry.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Entry
的用法示例。
在下文中一共展示了Entry.insert方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_entry
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def add_entry(self, text):
entry = Entry(self)
entry.insert(0, ",".join(text))
entry.pack(fill="both", expand=True)
entry.config(state="readonly")
self.bindings(entry)
self.entries.append(entry)
示例2: DateWidget
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
class DateWidget(Frame):
"""Gets a date from the user."""
def __init__(self, master):
"""Make boxes, register callbacks etc."""
Frame.__init__(self, master)
self.label = Label(self, text="När är du född?")
self.label.pack()
self.entry_text = StringVar()
self.entry_text.trace("w", lambda *args: self.onEntryChanged())
self.entry = Entry(self, width=date_entry_width,
textvariable=self.entry_text)
self.entry.insert(0, "ÅÅÅÅ-MM-DD")
self.entry.pack(pady=small_pad)
self.button = Button(self, text="Uppdatera",
command=lambda: self.onDateChanged())
self.button.pack()
self.entry.focus_set()
self.entry.select_range(0, END)
self.entry.bind("<Return>", lambda x: self.onDateChanged())
def setListener(self, pred_view):
"""Select whom to notify when a new date is entered."""
self.pred_view = pred_view
def onDateChanged(self):
"""Notifies the PredictionWidget that the date has been changed."""
try:
date = datetime.datetime.strptime(self.entry.get(),
"%Y-%m-%d").date()
self.pred_view.update(date)
except ValueError:
self.entry.configure(foreground="red")
def onEntryChanged(self):
"""Reset the text color."""
self.entry.configure(foreground="")
示例3: insert_entry_field
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def insert_entry_field(self, txt, default=None):
frame = Frame(self.frame)
frame.pack(fill="x")
label = Label(frame, text=txt, width=6)
label.pack(side="left", anchor="n", padx=5, pady=5)
entry = Entry(frame)
entry.pack(fill="x", padx=5, pady=5, expand=True)
if default:
entry.insert("end", default)
self.entries["Entry"][txt] = entry
示例4: escrever_mascara_entry
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def escrever_mascara_entry(evento_char, ref_entry: ttk.Entry, mascara: str, especial: str = ''):
""" Método estático para formatar a entrada de um Entry de acordo com mascara.
Pode ser usado sem instanciação.
:param evento_char: event.char do evento.
:param ref_entry: Referência do componente Entry.
:param mascara: Mascara base para a formatação. Deve apresentar espacos onde quer ser inseridos os números.
:return: none. """
# Apaga o Entry caso o conteúdo seja o default.
if ref_entry.get() == mascara:
ref_entry.delete(0, 'end')
# O event.char captura de tecla literalmente, mas não captura teclas de controle(Backspace, ...).
# O event.keysym usa uma nomenclatura diferente, e captura todas as teclas.
# Tkinter 8.5 reference gui for Python. 161-162.
if evento_char in string.digits or evento_char in especial:
pos = len(ref_entry.get())
try:
if mascara[pos] != ' ':
ref_entry.insert('end', mascara[pos])
except IndexError:
ref_entry.delete(0, 'end')
示例5: text_query
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def text_query(self, query_lable, original_text=None, accept_func=None):
if self._query is not None:
return
frame = Frame(self.menubar)
label = Label(frame, text=query_lable)
label.grid(column=0, row=0, sticky=(N, S))
self._accept_func = accept_func
entry = Entry(frame)
if original_text is not None:
entry.insert(0, original_text)
entry.original_value = original_text
entry.grid(column=1, row=0, sticky=(N,S,W,E))
kb.make_bindings(kb.text_query,
{'accept': self.accept_query,
'cancel': lambda e: self.close_query()}, entry.bind)
frame.grid(column=self._menucolumn, row=0)
self._menucolumn += 1
entry.focus_set()
self._query = frame
示例6: Example
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
class Example(Frame):
def __init__(self, parent, q):
Frame.__init__(self, parent)
self.queue = q
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Pi computation")
self.pack(fill=BOTH, expand=True)
self.grid_columnconfigure(4, weight=1)
self.grid_rowconfigure(3, weight=1)
lbl1 = Label(self, text="Digits:")
lbl1.grid(row=0, column=0, sticky=E, padx=10, pady=10)
self.ent1 = Entry(self, width=10)
self.ent1.insert(END, "4000")
self.ent1.grid(row=0, column=1, sticky=W)
lbl2 = Label(self, text="Accuracy:")
lbl2.grid(row=0, column=2, sticky=E, padx=10, pady=10)
self.ent2 = Entry(self, width=10)
self.ent2.insert(END, "100")
self.ent2.grid(row=0, column=3, sticky=W)
self.startBtn = Button(self, text="Start",
command=self.onStart)
self.startBtn.grid(row=1, column=0, padx=10, pady=5, sticky=W)
self.pbar = Progressbar(self, mode='indeterminate')
self.pbar.grid(row=1, column=1, columnspan=3, sticky=W+E)
self.txt = scrolledtext.ScrolledText(self)
self.txt.grid(row=2, column=0, rowspan=4, padx=10, pady=5,
columnspan=5, sticky=E+W+S+N)
def onStart(self):
self.startBtn.config(state=DISABLED)
self.txt.delete("1.0", END)
self.digits = int(self.ent1.get())
self.accuracy = int(self.ent2.get())
self.p1 = Process(target=self.generatePi, args=(self.queue,))
self.p1.start()
self.pbar.start(DELAY2)
self.after(DELAY1, self.onGetValue)
def onGetValue(self):
if (self.p1.is_alive()):
self.after(DELAY1, self.onGetValue)
return
else:
try:
self.txt.insert('end', self.queue.get(0))
self.txt.insert('end', "\n")
self.pbar.stop()
self.startBtn.config(state=NORMAL)
except queue.Empty:
print("queue is empty")
def generatePi(self, queue):
getcontext().prec = self.digits
time.sleep(10)
pi = Decimal(0)
k = 0
n = self.accuracy
while k < n:
pi += (Decimal(1)/(16**k))*((Decimal(4)/(8*k+1)) -
(Decimal(2)/(8*k+4)) -
(Decimal(1)/(8*k+5)) -
(Decimal(1)/(8*k+6)))
k += 1
print(self.p1.is_alive())
queue.put(pi)
print("end")
示例7: add_entry
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def add_entry(self, text):
entry = Entry(self)
entry.insert(0, "".join(text))
entry.pack(fill="both", expand=True)
entry.config(state="disable")
self.entries.append(entry)
示例8: MarkovDemo
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
#.........这里部分代码省略.........
self.encoding_frame.grid_remove()
else:
self.encoding_frame.grid()
def handle_key_events(self, event):
"Schedule refreshing the output area after an input area event."
if event is None or event.char and event.state | 0o11 == 0o11:
self.after_idle(self.refresh)
@staticmethod
def handle_control_a(event):
"Select all text in the widget associated with the given event."
event.widget.tag_add(SEL, 1.0, END + '-1c')
return 'break'
########################################################################
# Handle interface's updates when either encoding or decoding.
def refresh(self):
"Refresh the output based on the value of the input."
text = self.input_text.get(1.0, END + '-1c')
if not text:
self.output = text
elif self.encrypting:
self.encode(text)
else:
self.decode(text)
def output(self, value):
"Set the text in the output area to the string value."
self.output_text['state'] = NORMAL
self.output_text.delete(1.0, END)
self.output_text.insert(END, value)
if self.encrypting and self.freeze_var.get():
self.output_text.see(END)
self.output_text['state'] = DISABLED
output = property(fset=output, doc='Output area property.')
@property
def chain_size(self):
"Chain size for the Markov chains used when encrypting."
try:
value = ast.literal_eval(self.chain_size_entry.get())
assert isinstance(value, int) and 2 <= value <= 256
return value
except:
self.chain_size_entry.delete(0, END)
self.chain_size_entry.insert(0, '2')
return 2
@property
def plain_text(self):
"Plain text or ignored characters in encryption process."
try:
value = self.repr_to_obj(self.plain_text_entry.get(), '')
assert isinstance(value, str)
return value
except:
self.plain_text_entry.delete(0, END)
return ''
########################################################################
# Encrypt a string for display in the interface's output area.
示例9: ModelFrame
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
class ModelFrame(LabelFrame):
topPadding = 12
def __init__(self,parent):
LabelFrame.__init__(self,parent,text="Model",borderwidth=5)
self.selection = tkinter.IntVar()
self.exponential = Radiobutton(self,text="Exponential model",variable=self.selection,value=Model.EXP.value,command=self.changeSelection)
self.powerlaw = Radiobutton(self,text="Power law model",variable=self.selection,value=Model.POW.value,command=self.changeSelection)
self.weibull = Radiobutton(self,text="Weibull model",variable=self.selection,value=Model.WEI.value,command=self.changeSelection)
self.exponential.grid(row=0,column=0,sticky="W",padx=10,pady=(self.topPadding,5))
self.powerlaw.grid(row=1,column=0,sticky="W",padx=10,pady=5)
self.weibull.grid(row=2,column=0,sticky="W",padx=10,pady=(5,0))
seperator = Separator(self, orient=tkinter.VERTICAL)
seperator.grid(row=0, column=1, rowspan=3, sticky="NS", padx=(20,10), pady=(self.topPadding,0))
## Exponential setup
self.expNumberOfSegments_L = Label(self,text="Number of segments: ")
self.expNumberOfSegments_E = Entry(self,width=5, justify="right")
self.expNumberOfSegments_E.insert(0, settings.EXP_DEFAULT_NUMBER_OF_SEGMENTS)
self.expWidgets = [self.expNumberOfSegments_L,self.expNumberOfSegments_E]
## Power law setup
self.powProximalLimit_L = Label(self,text="Proximal limit of integration: ")
self.powProximalLimit_E = Entry(self,width=5, justify="right")
self.powDistalLimit_L = Label(self,text="Distal limit of integration: ")
self.powDistalLimit_E = Entry(self,width=5, justify="right")
self.powProximalLimit_E.insert(0, settings.POW_DEFAULT_PROXIMAL_LIMIT)
self.powDistalLimit_E.insert(0, settings.POW_DEFAULT_DISTAL_LIMIT)
self.powWidgets = [self.powProximalLimit_L,self.powProximalLimit_E,
self.powDistalLimit_L,self.powDistalLimit_E]
## Weibull setup
self.weiNumberOfRuns_L = Label(self,text="Number of runs: ")
self.weiNumberOfRuns_E = Entry(self,width=5, justify="right")
self.weiIterationsPerRun_L = Label(self,text="Iterations per run: ")
self.weiIterationsPerRun_E = Entry(self,width=5, justify="right")
self.weiEstimatedTime_L = Label(self,text="Estimated time (s): ")
self.weiEstimatedTime_E = CustomEntry(self,width=5, justify="right")
self.weiEstimatedTime_E.setUserEditable(False)
self.weiLambdaLowerBoundL = Label(self,text="\u03BB lower bound:")
self.weiLambdaUpperBoundL = Label(self,text="\u03BB upper bound:")
self.weiLambdaLowerBoundE = Entry(self,width=5, justify="right")
self.weiLambdaUpperBoundE = Entry(self,width=5, justify="right")
self.weiKLowerBoundL = Label(self,text="k lower bound:")
self.weiKUpperBoundL = Label(self,text="k upper bound:")
self.weiKLowerBoundE = Entry(self,width=5, justify="right")
self.weiKUpperBoundE = Entry(self,width=5, justify="right")
self.weiNumberOfRuns_E.insert(0, settings.WEI_DEFAULT_NUMBER_OF_RUNS)
self.weiIterationsPerRun_E.insert(0, settings.WEI_DEFAULT_ITERATIONS_PER_RUN)
self.weiLambdaLowerBoundE.insert(0, settings.WEI_DEFAULT_LAMBDA_LOWER_BOUND)
self.weiLambdaUpperBoundE.insert(0, settings.WEI_DEFAULT_LAMBDA_UPPER_BOUND)
self.weiKLowerBoundE.insert(0, settings.WEI_DEFAULT_K_LOWER_BOUND)
self.weiKUpperBoundE.insert(0, settings.WEI_DEFAULT_K_UPPER_BOUND)
self.weiWidgets = [self.weiNumberOfRuns_L,self.weiNumberOfRuns_E,
self.weiIterationsPerRun_L,self.weiIterationsPerRun_E,
self.weiEstimatedTime_L,self.weiEstimatedTime_E,
self.weiLambdaLowerBoundL,self.weiLambdaUpperBoundL,self.weiLambdaLowerBoundE,self.weiLambdaUpperBoundE,
self.weiKLowerBoundL,self.weiKUpperBoundL,self.weiKLowerBoundE,self.weiKUpperBoundE]
## General
self.currentWidgets = []
self.selection.set(Model.EXP.value)
self.changeSelection()
def changeSelection(self):
for widget in self.currentWidgets:
widget.grid_remove()
modelType = Model(self.selection.get())
sX = 10
bX = 20
if modelType == Model.EXP:
self.expNumberOfSegments_L.grid(row=0,column=2,padx=(bX,sX),pady=(self.topPadding,5),sticky="W")
self.expNumberOfSegments_E.grid(row=0,column=3,padx=(sX,bX),pady=(self.topPadding,5),sticky="W")
self.currentWidgets = self.expWidgets
elif modelType == Model.POW:
self.powProximalLimit_L.grid(row=0,column=2,padx=(bX,sX),pady=(self.topPadding,5),sticky="W")
self.powProximalLimit_E.grid(row=0,column=3,padx=(sX,bX),pady=(self.topPadding,5),sticky="W")
#.........这里部分代码省略.........
示例10: initUI
# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import insert [as 别名]
def initUI(self):
self.parent.title("Calculator")
Style().configure("TButton", padding=(0, 5, 0, 5), font='serif 10')
self.columnconfigure(0, pad=3)
self.columnconfigure(1, pad=3)
self.columnconfigure(2, pad=3)
self.columnconfigure(3, pad=3)
self.columnconfigure(4, pad=3)
self.columnconfigure(5, pad=3)
self.rowconfigure(0, pad=3)
entry1 = Entry(self)
#entry.grid(row=0, columnspan=4, sticky=W+E)
entry1.insert(0, "0")
entry2 = Entry(self)
entry2.insert(0, "0")
Team_1_Score = 0
Team_2_Score = 0
def Addition_1():
nonlocal Team_1_Score
Team_1_Score += 1
entry1.delete(0, 3)
entry1.insert(0, Team_1_Score)
F = open("Team1.txt", "w")
F.write(str(Team_1_Score))
F.close()
def Substraction_1():
nonlocal Team_1_Score
Team_1_Score -= 1
entry1.delete(0, 3)
entry1.insert(0, Team_1_Score)
F = open("Team1.txt", "w")
F.write(str(Team_1_Score))
F.close()
def Addition_2():
nonlocal Team_2_Score
Team_2_Score += 1
entry2.delete(0, 3)
entry2.insert(0, Team_2_Score)
F = open("Team2.txt", "w")
F.write(str(Team_2_Score))
F.close()
def Substraction_2():
nonlocal Team_2_Score
Team_2_Score -= 1
entry2.delete(0, 3)
entry2.insert(0, Team_2_Score)
F = open("Team2.txt", "w")
F.write(str(Team_2_Score))
F.close()
def display_1():
return Team_1_Score
def display_2():
return Team_2_Score
One_Pls = Button(self, text="+", command = Addition_1)
One_Pls.grid(row=0, column=0)
One_Mns = Button(self, text="-", command = Substraction_1)
One_Mns.grid(row=0, column=1)
#One_Display = Button(self, text="=", command = display_1)
entry1.grid(row=0, column=2)
Two_Pls = Button(self, text="+", command = Addition_2)
Two_Pls.grid(row=0, column=3)
Two_Mns = Button(self, text="-", command = Substraction_2)
Two_Mns.grid(row=0, column=4)
#Two_Display = Button(self, text="=", command = display_2)
entry2.grid(row=0, column=5)
self.pack()