本文整理汇总了Python中tkinter.Entry.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.insert方法的具体用法?Python Entry.insert怎么用?Python Entry.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Entry
的用法示例。
在下文中一共展示了Entry.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: body
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
def body(self, master):
self.results = []
Label(master, text="td:").grid(row=0)
Label(master, text="tb:").grid(row=1)
Label(master, text="tt:").grid(row=2)
Label(master, text="head:").grid(row=3)
Label(master, text="nose:").grid(row=4)
Label(master, text="ul:").grid(row=5)
Label(master, text="ll:").grid(row=6)
Label(master, text="jaw:").grid(row=7)
Label(master, text="lc:").grid(row=8)
Label(master, text="rc:").grid(row=9)
Label(master, text="l ear:").grid(row=10)
Label(master, text="r ear:").grid(row=11)
vcmd = (self.master.register(self.validateEntry),'%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
for i in range(0,12):
a = Entry(master)
setattr(self, "e"+str(i),a)
a.insert(0,i+1)
a.config(validate='key',validatecommand=vcmd)
a.grid(row=i,column=1)
return self.e0 # initial focus
示例2: PlusTwo
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class PlusTwo(Frame):
def __init__(self):
'the constructor for the GUI'
Frame.__init__(self)
self.make_widgets()
self.pack()
def make_widgets(self):
'create the widgets for the GUI'
Label(self, text="Please enter a numeric expression:").pack()
self.ent = Entry(self)
self.ent.pack()
Button(self, text="+2", command=self.addtwo).pack(side=LEFT)
Button(self, text="Clear", command=lambda: self.ent.delete(0, END)).pack(side=RIGHT)
# Write this method
def addtwo(self):
'the event handler for the +2 button'
try:
val=eval(self.ent.get())
res=val+2
self.ent.delete(0,END)
self.ent.insert(END,res)
except:
showinfo(title='Error',message='You need to enter numeric values!')
self.ent.delete(0,END)
示例3: Edit_Machine_Modal
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class Edit_Machine_Modal(Modal):
def __init__(self, parent=None, title="Edit Machine"):
Modal.__init__(self, parent, title, geometry="580x110" if system() == "Windows" else "485x95")
def initialize(self):
label = Label(self, font=("TkTextFont", 13), text="Machine Name: ")
label.grid(row=0, column=0, pady=10)
self.machine_name_box = Entry(self, font=("TkTextFont", 13), width=32)
self.machine_name_box.grid(row=0, column=1, pady=10, sticky="EW")
self.machine_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):
new_name = self.machine_name_box.get()
if new_name is not None and new_name != "" and new_name != self.current_name:
self.new_name = self.machine_name_box.get()
self.destroy()
def cancel(self, event=None):
self.new_name = None
self.destroy()
def show(self, current_name):
self.current_name = current_name
self.machine_name_box.insert(0, self.current_name)
Modal.show(self)
return self.new_name
示例4: ProgramWidget
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class ProgramWidget(Frame):
def __init__(self, parent, client):
super(ProgramWidget, self).__init__(parent)
self.client = client
self.client.onProgramChange = self.programChanged
self.programLabel = Label(self, text = 'Program:')
self.programLabel.grid(row = 0, column = 0)
self.programEntry = Entry(self, text = 'Program name',
state = 'readonly')
self.programEntry.grid(row = 0, column = 1)
self.buttonPanel = Frame(self)
self.buttonPanel.grid(row = 1, column = 0, columnspan = 2, sticky = W)
self.newButton = Button(self.buttonPanel, text='New',
command = self.newProgram)
self.newButton.pack(side = LEFT)
def programChanged(self):
self.__setProgramText(str(self.client.state))
def __setProgramText(self, text):
self.programEntry.configure(state = NORMAL)
self.programEntry.delete(0)
self.programEntry.insert(0, text)
self.programEntry.configure(state = 'readonly')
def newProgram(self):
self.client.makeNewProgram()
示例5: GuiGenerateCount
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class GuiGenerateCount(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.pack()
#step increment len
self._stepLenFrm = Frame(self); self._stepLenFrm.pack()
self._stepLenLbl = Label(self._stepLenFrm, text="Step Len: "); self._stepLenLbl.pack(side=LEFT)
self._stepLenSpin = Spinbox(self._stepLenFrm, from_=0, to=1000); self._stepLenSpin.pack(side=LEFT)
#start value
self._startFrm = Frame(self); self._startFrm.pack()
self._startLbl = Label(self._startFrm, text="Start Value: "); self._startLbl.pack(side=LEFT)
self._startTxt = Entry(self._startFrm); self._startTxt.pack(side=LEFT)
self._startTxt.insert(0, "0")
def getSettings(self):
return { "StepLen": self._stepLenSpin.get(),
"StartValue": self._startTxt.get()
}
def getName(self):
return "Counter"
def getGeneratorFunction(self):
return generateCounter
示例6: Scroller
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class Scroller(object):
"""
Scrolls through a solution list.
"""
def __init__(self, wdw, sols):
"""
Stores the list of solutions in sols
and defines the layout of the GUI.
"""
wdw.title('solutions scroller')
self.sols = sols
self.cursor = 0
self.lbl = Label(wdw, text="solution : ")
self.lbl.grid(row=0, column=0, sticky=E)
self.ent = Entry(wdw)
self.ent.grid(row=0, column=1, stick=W)
self.ent.insert(INSERT, "0 of %d" % len(sols))
self.myft = Font(family="Courier New", size=12, weight="normal")
self.mlen = self.myft.measure("M")
lines = sols[0].split('\n')
self.width = max([len(line) for line in lines])
self.display = StringVar()
self.display.set(self.sols[0])
self.mess = Message(wdw, textvariable=self.display, \
font=self.myft, width=self.width*self.mlen, background='white')
self.mess.grid(row=1, column=0, columnspan=2)
self.btnext = Button(wdw, command=self.next, text='next')
self.btnext.grid(row=2, column=1, sticky=W+E)
self.btprev = Button(wdw, command=self.previous, text='previous')
self.btprev.grid(row=2, column=0, sticky=W+E)
def show(self):
"""
Shows the solution at position self.cursor
in the message widget and updates the entry widget.
"""
self.display.set(self.sols[self.cursor])
self.ent.delete(0, END)
self.ent.insert(INSERT, '%d of %d' % (self.cursor, len(self.sols)))
def next(self):
"""
Increases the cursor by one if possible.
"""
if self.cursor < len(self.sols) - 1:
self.cursor = self.cursor + 1
self.show()
def previous(self):
"""
Decreases the cursor by one if possible.
"""
if self.cursor > 0:
self.cursor = self.cursor - 1
self.show()
示例7: GuiBasicSettings
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class GuiBasicSettings(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.pack()
#Unit
self.sizeUnits = {"Byte": 1, "KiB":1024, "MiB":1024**2, "GiB":1024**3}
self._initFile()
self._initSize()
def _initFile(self):
self._fileLbl = Label(self, text="File: ")
self._fileTxt = Entry(self)
self._fileTxt.insert(0, "/tmp/out.txt")
self._fileBtn = Button(self, text="Create", command=self._callbackFun)
self._fileLbl.grid(row=0, column=0)
self._fileTxt.grid(row=0, column=1)
self._fileBtn.grid(row=0, column=2)
def _initSize(self):
self._sizeLbl = Label(self, text="FileSize: ")
self._sizeTxt = Entry(self)
self._sizeTxt.insert(0, "1024")
self._sizeVar = StringVar()
self._sizeVar.set("Byte") #FIXME: replace "Byte" with variable
sizeOptParam = (self, self._sizeVar) + tuple(self.sizeUnits.keys())
self._sizeOptMen = OptionMenu(*sizeOptParam)
self._sizeLbl.grid(row=1, column=0)
self._sizeTxt.grid(row=1, column=1)
self._sizeOptMen.grid(row=1, column=2)
def _callbackFun(self):
print("_callbackBtn")
self.outerCallback()
def enableButton(self, enabled=True):
if enabled:
self._fileBtn.config(state="normal")
else:
self._fileBtn.config(state="disabled")
def getFileName(self):
return self._fileTxt.get()
def getFileSize(self):
mult = int(self.sizeUnits[self._sizeVar.get()])
val = int(self._sizeTxt.get())
return val * mult
def setCallback(self, aCallback):
self.outerCallback = aCallback
示例8: editSettings
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
def editSettings(cls):
def commitSettings(messageInDialogIn):
try:
SettingsVars.DEFAULT_BOARD = defaultBoardBox.get()
SettingsVars.REFRESH_INTERVAL = int(refreshIntervalBox.get())
messageInDialogIn.destroy()
except ValueError:
messagebox.showwarning(message="Invalid Settings")
messageInDialogIn.focus_force()
settingsDialog = Tk()
settingsDialog.title('Settings')
try:
if os.name == "nt":
settingsDialog.wm_iconbitmap(bitmap='./gui/images/icon.ico')
except _tkinter.TclError:
pass
settingsDialog.columnconfigure(0, weight=1)
settingsDialog.rowconfigure(0, weight=1)
settingsDialog.minsize(width=100, height=50)
frame = Frame(settingsDialog)
refreshIntervalLabel = Label(frame)
refreshIntervalLabel['text'] = 'Refresh Interval'
refreshIntervalLabel.pack()
refreshIntervalBox = Entry(frame)
refreshIntervalBox.insert(0, cls.REFRESH_INTERVAL)
refreshIntervalBox.pack(fill='both')
defaultBoardLabel = Label(frame)
defaultBoardLabel['text'] = 'Default Board'
defaultBoardLabel.pack()
defaultBoardBox = Entry(frame)
defaultBoardBox.insert(0, cls.DEFAULT_BOARD)
defaultBoardBox.pack(fill='both')
submitButton = Button(frame)
submitButton['text'] = 'Ok'
submitButton['command'] = lambda: commitSettings(settingsDialog)
submitButton.pack(side="left", expand="yes", fill="both", padx=5, pady=3)
cancelButton = Button(frame)
cancelButton['text'] = 'Cancel'
cancelButton['command'] = settingsDialog.destroy
cancelButton.pack(fill='both', expand="yes", padx=5, pady=3)
frame.pack(fill='both', expand="yes", padx=0, pady=0)
return settingsDialog
示例9: makeform
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field[0], anchor='w')
ent = Entry(row)
row.pack(side=TOP, fill=X, padx=5, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
ent.config(show=field[1])
ent.insert(0, field[2])
entries.append((field[0], ent))
return entries
示例10: AddManually
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class AddManually(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
self.configure(relief=GROOVE)
self.configure(borderwidth="2")
self.configure(relief=GROOVE)
self.configure(width=125)
self.label_top = Label(self)
self.label_top.place(relx=0.4, rely=0.03, height=21, width=112)
self.label_top.configure(text="Add items manually")
self.name = Entry(self, fg='grey')
self.name.place(relx=0.05, rely=0.31, relheight=0.08, relwidth=0.29)
self.name.insert(0, "Input name here")
self.name.bind('<Button-1>', lambda event: greytext(self.name))
self.link = Entry(self, fg='grey')
self.link.place(relx=0.65, rely=0.31, relheight=0.08, relwidth=0.29)
self.link.insert(0, "Input link here")
self.link.bind('<Button-1>', lambda event: greytext(self.link))
self.add_btn = Button(self, command=self.send_data)
self.add_btn.place(relx=0.42, rely=0.44, height=34, width=100)
self.add_btn.configure(text="Add item")
self.back = Button(self, command=lambda: controller.show_frame('Main'))
self.back.place(relx=0.42, rely=0.64, height=34, width=100)
self.back.configure(text="Go back")
name_label = Label(self)
name_label.place(relx=0.05, rely=0.22, height=21, width=38)
name_label.configure(text="Name")
link_label = Label(self)
link_label.place(relx=0.65, rely=0.22, height=21, width=28)
link_label.configure(text="Link")
def send_data(self):
if self.link.cget('fg') == 'grey' or self.name.cget('fg') == 'grey':
return
link = self.link.get()
if link.strip() != '':
name = self.name.get()
self.controller.add_item(link, name)
print("Item added")
示例11: SettingsDialog
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class SettingsDialog(simpledialog.Dialog):
def __init__(self, *args, **kwargs):
self.config = kwargs.pop("config")
self.config_file_name = kwargs.pop("config_file_name")
super(SettingsDialog, self).__init__(*args, **kwargs)
def body(self, master):
Label(master, text="Team").grid(row=0)
Label(master, text="Case").grid(row=1)
# self.case_entry = Entry(master, textvariable=self.case).grid(row=0, column=1)
# self.case_entry = Entry(master, textvariable=self.case).grid(row=1, column=1)
self.case_entry = Entry(master)
self.case_entry.grid(row=0, column=1)
try:
self.case_entry.insert(0, self.config.get("DEFAULT", "case"))
except configparser.NoOptionError:
self.case_entry.insert(0, "CASE")
self.team_entry = Entry(master)
self.team_entry.grid(row=1, column=1)
try:
self.team_entry.insert(0, self.config.get("DEFAULT", "team"))
except configparser.NoOptionError:
self.team_entry.insert(0, "TEAM")
return self.case_entry # Focus
def apply(self):
self.config.set("DEFAULT", "case", self.case_entry.get())
self.config.set("DEFAULT", "team", self.team_entry.get())
with open(self.config_file_name, 'w') as configfile:
self.config.write(configfile)
示例12: CreateSets
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class CreateSets(Frame):
def __init__(self, parent):
# super(createSets,self).__init__(parent)
Frame.__init__(self, parent)
self.parent = parent
self.grid(row=0, column=0)
self.parentWindow = 0
self.listBox = Listbox(self, selectmode=EXTENDED)
self.listBox.grid(row=1, column=1)
for item in ["one", "two", "three", "four"]:
self.listBox.insert(END, item)
self.buttonDel = Button(self,
text="delite selected class",
command=self.del_selected) # lambda ld=self.listBox:ld.delete(ANCHOR))
self.buttonDel.grid(row=0, column=0)
self.entry = Entry(self, state=NORMAL)
# self.entry.focus_set()
self.entry.insert(0, "default")
self.entry.grid(row=1, column=0)
self.buttonInsert = Button(self, text="add new class",
command=self.add)
self.buttonInsert.grid(row=0, column=1)
self.buttonDone = Button(self, text="done", command=self.done)
self.buttonDone.grid(row=2, column=0)
def done(self):
self.parentWindow.childResultList = self.listBox.get(0, END)
# print(self.listBox.get(0, END))
self.parent.destroy()
def add(self):
text = self.entry.get()
self.listBox.insert(END, text)
def del_selected(self):
lb = self.listBox
items = map(int, lb.curselection())
for item in items:
lb.delete(item)
示例13: Frame_SelectFilename
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class Frame_SelectFilename(LabelFrame):
"""Select a filename and path for the new Datastore file.
Attributes
----------
filename : str
The full path and filename to the database file.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._isReady = False
self.filename = None
Grid.columnconfigure(self, 1, weight = 1)
self.button = Button(self, text="Browse",
command=self.loadFile, width=10)
self.button.grid(row = 0, column=1,
padx = 5, pady = 5, sticky = E)
self.entry = Entry(self, width = 65)
self.entry.delete(0, END)
self.entry.insert(0, 'Enter a path to a new datastore file...')
self.entry.grid(row = 0, column = 0,
padx = 5, pady = 5, sticky = W)
self.entry.configure(state = 'readonly')
@property
def isReady(self):
return self._isReady
def loadFile(self):
fname = asksaveasfilename(filetypes=(('HDF5 files', '*.h5'),
('All files', '*.*')),
title = 'Select a new file...',
initialfile = 'datastore.h5')
if fname:
self.filename = fname
self.entry.configure(state = 'normal')
self.entry.delete(0, END)
self.entry.insert(0, fname)
self.entry.configure(state = 'readonly')
self._isReady = True
示例14: Frame_SelectSearchPath
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [as 别名]
class Frame_SelectSearchPath(LabelFrame):
"""Select a path to search for files to build the database with.
Attributes
----------
searchPath : str
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._isReady = False
self.searchPath = None
Grid.columnconfigure(self, 1, weight = 1)
self.button = Button(self, text="Browse",
command=self.loadFile, width=10)
self.button.grid(row=0, column=1,
padx = 5, pady = 5, sticky = E)
self.entry = Entry(self, width = 65)
self.entry.delete(0, END)
self.entry.insert(
0, 'Enter the directory containing the input files...')
self.entry.grid(row = 0, column = 0,
padx = 5, pady = 5, sticky = W)
self.entry.configure(state = 'readonly')
@property
def isReady(self):
return self._isReady
def loadFile(self):
fname = askdirectory(title = 'Select a search directory...',
mustexist = True)
if fname:
self.searchPath = fname
self.entry.configure(state = 'normal')
self.entry.delete(0, END)
self.entry.insert(0, fname)
self.entry.configure(state = 'readonly')
self._isReady = True
示例15: Edit_Ingredient_Modal
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import insert [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)