本文整理汇总了Python中tkinter.Entry.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.delete方法的具体用法?Python Entry.delete怎么用?Python Entry.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Entry
的用法示例。
在下文中一共展示了Entry.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BMI
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class BMI(Frame):
'Body Mass Index app'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.grid()
BMI.make_widgets(self)
def make_widgets(self):
'defines BMI widgets'
Label(self,text='Enter your height: ').grid(row=0,column=0)
self.htEnt=Entry(self)
self.htEnt.grid(row=0,column=1)
Label(self,text='Enter your weight: ').grid(row=1,column=0)
self.wtEnt=Entry(self)
self.wtEnt.grid(row=1,column=1)
Button(self,text='Compute BMI',command=self.compute).grid(row=2,column=0,columnspan=2)
def compute(self):
'the handler for button "Compute BMI"'
try:
hgt=eval(self.htEnt.get())
wgt=eval(self.wtEnt.get())
res=wgt*703/hgt**2
showinfo(title='Result',message='Your BMI is {}'.format(res))
except:
showinfo(title='Ooops!',message='Invalid number!')
self.wtEnt.delete(0,END)
self.htEnt.delete(0,END)
示例2: PlusTwo
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [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: Demo
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Demo(Frame):
def __init__(self, parent, *args, **kw):
Frame.__init__(self, parent, *args,**kw)
self.e=Entry(self, text='Message')
self.e.delete(0,'end')
self.e.pack()
self.makebuttons()
self.pack(expand='true',fill='x')
def makebuttons(self):
self.b1=Button(self, text="restart",bg="blue",fg='white',command= self.restart )
self.b1.pack(side='right',fill='both' )
self.b2=Button(self,text='quit',bg='green',fg='white',command=self.quit)
self.b2.pack(side='left',fill='both')
self.lastTime=""
self.start_timer()
def start_timer(self):
pass
def destroy(self):
self.pack_forget()
def restart(self):
self.destroy()
D=Demo(root,bg='purple')
print ("killed")
D.__init__(self,root)
pass
def quit(self):
root.destroy()
示例4: ProgramWidget
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [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: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Calculator:
def __init__(self, master):
self.master = master
master.title("Calculator")
self.total = 0
self.entered_number = 0
self.total_label_text = IntVar()
self.total_label_text.set(self.total)
self.total_label = Label(master, textvariable=self.total_label_text)
self.label = Label(master, text="Total:")
vcmd = master.register(self.validate) # we have to wrap the command
self.entry = Entry(master, validate="key", validatecommand=(vcmd, "%P"))
self.add_button = Button(master, text="+", command=lambda: self.update("add"))
self.subtract_button = Button(master, text="-", command=lambda: self.update("subtract"))
self.multiply_button = Button(master, text="*", command=lambda: self.update("multiply"))
# self.divide_button = Button(master, text="/", command=lambda: self.update("divide"))
self.reset_button = Button(master, text="Reset", command=lambda: self.update("reset"))
# LAYOUT
self.label.grid(row=0, column=0, sticky=W)
self.total_label.grid(row=0, column=1, columnspan=2, sticky=E)
self.entry.grid(row=1, column=0, columnspan=5, sticky=W + E)
self.add_button.grid(row=2, column=0)
self.subtract_button.grid(row=2, column=1)
self.multiply_button.grid(row=2, column=2)
# self.divide_button.grid(row=2, column=3)
self.reset_button.grid(row=2, column=4, sticky=W + E)
def validate(self, new_text):
if not new_text: # the field is being cleared
self.entered_number = 0
return True
try:
self.entered_number = int(new_text)
return True
except ValueError:
return False
def update(self, method):
if method == "add":
self.total += self.entered_number
elif method == "subtract":
self.total -= self.entered_number
elif method == "multiply":
self.total *= self.entered_number
elif method == "divide":
self.total /= self.entered_number
else: # reset
self.total = 0
self.total_label_text.set(self.total)
self.entry.delete(0, END)
示例6: Scroller
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [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: Calculator
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Calculator(Frame):
"""
The calculator has a layout like this:
< display >
7 8 9 *
4 5 6 /
1 2 3 -
0 = + C
"""
def __init__(self, parent = None):
Frame.__init__(self, parent)
self.make_widgets()
self.grid()
def make_widgets(self):
btn_list = [
'7', '8', '9', '*',
'4', '5', '6', '/',
'1', '2', '3', '-',
'0', '=', '+', 'C']
# create all buttons with a loop
r = 1
c = 0
for b in btn_list:
rel = 'ridge'
cmd = lambda x=b: self.click(x)
Button(self,text=b,width=7, relief = rel,command=cmd).grid(row=r,column=c)
c += 1
if c > 3:
c = 0
r += 1
# use Entry widget for an editable display
self.entry = Entry(self, width=33)#, bg="lightblue", fg ="blue")
self.entry.grid(row=0, column=0, columnspan=4)
def click(self, key):
if key == '=':
try:
result = eval(self.entry.get())
self.entry.insert(END, " = " + str(result))
except:
self.entry.insert(END, "--> Error!")
elif key == 'C':
self.entry.delete(0, END) # clear entry
else:
# The previous calculation has been done, so clear entry
if '=' in self.entry.get():
self.entry.delete(0, END)
self.entry.insert(END, key)
示例8: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.entry = Entry(frame)
self.entry.pack(side=LEFT)
self.entry.bind('<Return>', self.on_click)
def on_click(self, event):
print('ENTER')
self.entry.delete(0, 'end')
示例9: Ed
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Ed(Frame):
'Simple arithmetic education app'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.pack()
Ed.make_widgets(self)
Ed.new_problem(self)
def make_widgets(self):
'defines Ed widgets'
self.exp=Entry(self)
self.exp.grid(row=0,column=0)
self.res=Entry(self)
self.res.grid(row=0,column=1)
Button(self,text='Enter',command=self.evaluate).grid(row=0,column=3)
def new_problem(self):
'creates new arithmetic problem'
temp1=randrange(1,10)
temp2=randrange(1,10)
if temp1 > temp2:
self.num1=temp1
self.num2=temp2
else:
self.num1=temp2
self.num2=temp1
coinflip=randrange(1,3)
if coinflip == 1:
self.exp.insert(0,self.num1)
self.exp.insert(END,' - ')
self.exp.insert(END,self.num2)
self.exp.insert(END,' =')
else:
self.exp.insert(0,self.num1)
self.exp.insert(END,' + ')
self.exp.insert(END,self.num2)
self.exp.insert(END,' =')
def evaluate(self):
'handles button "Enter" clicks by comparing answer in entry to correct result'
temp=self.exp.get()
exprs=temp[0:5]
try:
reslt=self.res.get()
if eval(exprs) == eval(reslt):
showinfo(title='Way to go!',message='That is correct!')
self.res.delete(0,END)
self.exp.delete(0,END)
Ed.new_problem(self)
else:
showinfo(title='Incorrect',message='Try again')
self.res.delete(0,END)
except:
showinfo(title='I\'m sorry. I didn\'t get that.',message='Please enter your answer using digits (0 through 9).')
self.res.delete(0,END)
示例10: Frame_SelectFilename
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [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
示例11: Frame_SelectSearchPath
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [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
示例12: Frame_SelectOptions
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Frame_SelectOptions(LabelFrame):
"""Selects the optional arguments for the build.
Attributes
----------
readTiffTags : tkinter
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._isReady = True
Grid.columnconfigure(self, 1, weight = 1)
self.button = Button(self, text='Help',
command=openMiscHelp, width=10)
self.button.grid(row = 0, column=1,
padx = 5, pady = 5, sticky = E)
self._kwargs = Entry(self, width = 65)
self._kwargs.delete(0, END)
self._kwargs.insert(0, '\'sep\' : \',\', \'readTiffTags\' : False')
self._kwargs.grid(row = 0, column = 0,
padx = 5, pady = 5, sticky = W)
@property
def isReady(self):
return self._isReady
@property
def kwargs(self):
"""Parses the textbox into a Python dict.
"""
return ast.literal_eval('{' + self._kwargs.get() + '}')
示例13: __init__
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._isReady = True
self.vsb = Scrollbar(self, orient="vertical")
self.text = Text(
self, height = 10,
yscrollcommand=self.vsb.set,
bg = self.master.cget('bg'),
wrap = 'word')
self.vsb.config(command=self.text.yview)
self.vsb.pack(side='right', fill='y')
self.text.pack(side='left', fill='both', expand=True)
# Create the list of checkboxes
self._listOfTypes = []
for currType in dsTypes.__all__:
v = BooleanVar(value = 1)
cb = Checkbutton(self, text = '%s' % currType, anchor = W,
width = 15, variable = v)
cb.var = v # Easy access to checkbox's current value
e = Entry(self)
e.delete(0, END)
e.insert(0, '<suffix>.<file_extension>')
self._listOfTypes.append((cb, e))
self.text.window_create('end', window=cb)
self.text.window_create('end', window=e)
self.text.insert('end', '\n') # Forces one checkbox per line
# Insert help message
self.text.insert('end', self.__doc__)
# This MUST follow insertion and positioning of
# the checkboxes/entries
self.text.config(state = DISABLED)
示例14: Game
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Game(Frame):
'Number guessing application'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.pack()
Game.make_widgets(self)
Game.new_game(self)
def make_widgets(self):
'defines Game widgets'
Label(self,text='Enter your guess:').pack()
self.ent=Entry(self)
self.ent.pack()
Button(self,text='Enter',command=self.reply).pack()
self.ent.bind('<Return>', lambda e: self.reply())
def new_game(self):
'starts a new game by choosing secret number'
self.secNum=randrange(1,101)
def reply(self):
'handles button "Enter" clicks'
try:
guess=eval(self.ent.get())
num=self.secNum
if guess > num:
showinfo(title='Report',message='{} is too high!'.format(guess))
elif guess < num:
showinfo(title='Report',message='{} is too low!'.format(guess))
else:
showinfo(title='Report',message='You got it!')
Game.new_game(self)
except:
showinfo(title='Ooops!',message='Invalid number!')
self.ent.delete(0,END)
示例15: Game
# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import delete [as 别名]
class Game(Frame):
'Number guessing application'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.pack()
self.count = 0
Game.make_widgets(self)
Game.new_game(self)
def make_widgets(self):
'Creates widgets. Creates a label, text box, and button'
self.header=Label(self, text='Enter your guess:')
self.header.pack()
self.guessEnt=Entry(self)
self.guessEnt.pack()
self.enter=Button(self, text='Enter', command=self.reply)
self.enter.pack()
def new_game(self):
'Resets counter, random number, and text box entry'
self.count=0
self.num=random.randint(0,100)
self.guessEnt.delete(0,END)
def reply(self):
'Takes input from test box and compares it against random number. Handles invalid numbers, and if the player wins, resets game.'
try:
guess=int(self.guessEnt.get())
if guess<self.num:
showinfo(title='Report', message='{} is too low.'.format(guess))
self.guessEnt.delete(0,END)
self.count+=1
if guess>self.num:
showinfo(title='Report', message='{} is too high.'.format(guess))
self.guessEnt.delete(0,END)
self.count+=1
if guess==self.num:
showinfo(title='Congratulations', message='You got it!\nIt took you {} tries.'.format(self.count))
Game.new_game(self)
except:
showinfo(title='Oooops!', message='Sorry, that number is invalid')
self.guessEnt.delete(0,END)