本文整理汇总了Python中tkinter.Toplevel.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python Toplevel.destroy方法的具体用法?Python Toplevel.destroy怎么用?Python Toplevel.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Toplevel
的用法示例。
在下文中一共展示了Toplevel.destroy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: destroy
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def destroy(self):
registry.delete(self)
Toplevel.destroy(self)
# If this is Idle's last window then quit the mainloop
# (Needed for clean exit on Windows 98)
if not registry.dict:
self.quit()
示例2: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class MailListWindow:
def __init__(self, title, after_close):
self.win = Toplevel()
self.win.title(title)
self.win.geometry('400x200')
self.win.wm_attributes('-toolwindow', True)
self.win.protocol("WM_DELETE_WINDOW", after_close)
inner_frame = tk.Frame(self.win)#inner_frame = tk.Frame(canvas)
inner_frame.pack(side='left', fill='both', expand = 1)
scrollbar = tk.Scrollbar(self.win,orient="vertical",command=self.scrolly)
scrollbar.pack(side='right', fill='y')
self.btn_count = 0
self.btns = []
self.texts = []
self.callbacks = []
self.frame = inner_frame
self.scrollbar = scrollbar
self.btn_per_page = 4
self.first_btn = 0
self.scrolly('', '0.0')
def scrolly(self, cmd, pos, what=''):
if self.btn_per_page <= self.btn_count:
bar_len = self.btn_per_page/self.btn_count
else:
bar_len=1
self.first_btn = int(float(pos)*self.btn_count)
pos = str(self.getScrollPos())
self.scrollbar.set(pos, str(float(pos)+bar_len))
for i in range(len(self.btns)):
mail_index = i+self.first_btn
self.btns[i].config(text=self.texts[mail_index], command=self.callbacks[mail_index])
def insertButton(self, text, callback):
if self.btn_count < self.btn_per_page:
btn = tk.Button(self.frame, bg='#fafafa',text=text, command=callback)
btn.pack(fill='both', expand=1)
self.btns.append(btn)
self.btn_count += 1
self.texts.append(text)
self.callbacks.append(callback)
self.scrolly('', self.getScrollPos())
def getScrollPos(self):
if self.btn_per_page >= self.btn_count:
return 0.0
if self.btn_count == 0:
return 0.0
return self.first_btn/self.btn_count
def callback(self):
print('click')
def destroy(self):
self.win.destroy()
示例3: ListDialog
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class ListDialog(object):
def __init__ (self, master, items, message, accept_func):
self.accept_func = accept_func
self.top = Toplevel(master)
self.top.transient(master)
self.top.rowconfigure(0, weight=1)
self.top.rowconfigure(1, weight=3)
self.top.rowconfigure(2, weight=0)
self.top.columnconfigure(0, weight=1)
self.top.columnconfigure(1, weight=1)
self.top.resizable(width=True, height=True)
self.frame = Frame(self.top)
self.frame.rowconfigure(0, weight=1)
self.frame.rowconfigure(1, weight=0)
self.frame.columnconfigure(0, weight=1)
self.frame.columnconfigure(1, weight=0)
self.frame.grid(row=0, column=0, sticky=(N, S, W, E), columnspan=2)
self.canvas = Canvas(self.frame)
self.canvas.create_text(0, 0, text=message, anchor=NW)
self.canvas.grid(row=0, column=0, sticky=(N, W, S, E))
self.vscroll = Scrollbar(self.frame, command=self.canvas.yview)
self.vscroll.grid(row=0, column=1, sticky=(N, S))
self.canvas['yscrollcommand'] = self.vscroll.set
self.hscroll = Scrollbar(self.frame, command=self.canvas.xview, orient=HORIZONTAL)
self.hscroll.grid(row=1, column=0, sticky=(W, E), columnspan=2)
self.canvas['xscrollcommand'] = self.hscroll.set
self.canvas['scrollregion'] = self.canvas.bbox('all')
self.canvas.bind('<Button-4>', self.scroll)
self.canvas.bind('<Button-5>', self.scroll)
self.canvas.bind('<MouseWheel>', self.scroll)
self.view = NameView(self.top, sorted(items))
self.view.widget.grid(row=1, column=0, columnspan=2, sticky=(N, W, E, S))
self.delbutton = Button(self.top, text='Ok', command=self.accept )
self.cancelbutton = Button(self.top, text='Cancel', command=self.cancel)
self.delbutton.grid(row=2, column=0)
self.cancelbutton.grid(row=2, column=1)
self.view.widget.focus_set()
def accept(self):
self.accept_func(self.view.selection())
self.top.destroy()
def cancel(self):
self.result = None
self.top.destroy()
def scroll(self, event):
if event.num == 4 or event.delta > 0:
self.canvas.yview(SCROLL, -1, UNITS)
elif event.num == 5 or event.delta < 0:
self.canvas.yview(SCROLL, 1, UNITS)
示例4: TkWindowNode
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class TkWindowNode(BaseWindowNode):
'''The base class of all the Window Node in the WaveSyn Object Model.
Properties:
tk_object: The underlying Tk Toplevel object;
node_path: The path of this node on the WaveSyn Object Model Tree.
Properties inherited from ModelNode:
root_node: The root node of the WaveSyn Object Model Tree.
'''
window_name = ''
_xmlrpcexport_ = ['close']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__tk_object = Toplevel()
self.__tk_object.title(f'{self.window_name} id={id(self)}')
self.__tk_object.protocol('WM_DELETE_WINDOW', self.on_close)
method_name_map = {
'update':'update',
'set_window_attributes':'wm_attributes'
}
for method_name in method_name_map:
locals()[method_name] = MethodDelegator('tk_object',
method_name_map[method_name])
def _close_callback(self):
pass
@Scripting.printable
def close(self):
#Scripting.root_node.on_window_quit(self)
if hasattr(self.parent_node, 'on_window_close'):
self.parent_node.on_window_close(self)
# For Toplevel objects, use destroy rather than quit.
if not self._close_callback():
self.__tk_object.destroy()
def on_close(self):
with code_printer():
self.close()
@property
def tk_object(self):
return self.__tk_object
def create_timer(self, interval=100, active=False):
return TkTimer(self.__tk_object, interval, active)
示例5: fetchMifParams
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def fetchMifParams(self):
mifTop = Toplevel()
self.mifApp = MifUI(mifTop)
self.mifApp.mainloop()
mifParams = self.mifApp.getParameters()
mifTop.destroy()
self.depth = int(mifParams[0])
self.width = int(mifParams[1])
self.address_radix = int(mifParams[2])
self.data_radix = int(mifParams[3])
self.fillZeros = int(mifParams[4])
示例6: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class SpeciesListDialog:
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.rowconfigure(1, weight=1)
Label(self.gui, text="Registered Species:").grid(row=0, column=0, pady=5, padx=5, sticky="w")
self.listRegisteredSpecies = Listbox(self.gui, width=70)
self.buttonAdd = Button(self.gui, text=" + ")
self.buttonDel = Button(self.gui, text=" - ")
self.listRegisteredSpecies.grid(row=1, column=0, columnspan=3, sticky="nswe", pady=5, padx=5)
self.buttonAdd.grid(row=2, column=1, pady=5, padx=5)
self.buttonDel.grid(row=2, column=2, pady=5, 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.actionUpdate(None)
self.gui.bind("<<Update>>", self.actionUpdate)
self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
self.buttonDel.bind("<ButtonRelease>", self.actionDel)
self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
self.gui.mainloop()
def actionClose(self):
self.parent.guiRoot.event_generate("<<Update>>", when="tail")
self.gui.destroy()
def actionUpdate(self, event):
self.listRegisteredSpecies.delete(0, "end")
for (taxid, name) in self.parent.optimizer.speciesList:
self.listRegisteredSpecies.insert("end", taxid + ": " + name)
def actionDel(self, event):
try:
selection = self.listRegisteredSpecies.selection_get()
selectionSplit = selection.split(": ")
self.parent.optimizer.speciesList.remove((selectionSplit[0], selectionSplit[1]))
self.gui.event_generate("<<Update>>")
except tkinter.TclError:
# no selection
pass
def actionAdd(self, Event):
SpeciesSearchDialog(self.parent, self)
示例7: splash
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class splash():
# try:
def __init__(self):
moduleDir = dirname(__file__)
moduleDir = moduleDir.rsplit('\\',2)[0]
image = moduleDir+'\\resources\\sirbot\\splash.gif'
self.root = Tk()
self.root.withdraw()
self.loadingSplash = Toplevel()
splashimage = PhotoImage(file=image)
self.loading = ttk.Label(self.loadingSplash,image=splashimage)
self.loadingSplash.overrideredirect(True)
self.loading.pack()
h = self.loading.winfo_screenheight()
w = self.loading.winfo_screenwidth()
self.loadingSplash.wm_attributes('-alpha',0.75)
self.loadingSplash.update_idletasks()
self.loadingSplash.geometry('262x112+'+str(int(w/2)-131*1)+
'+'+str(int(h/2)-56*1))
self.loadingSplash.update_idletasks()
self.loadingSplash.update()
# except:
## #log
## loadingSplash = Tk()
## #myfont = tkFont.families()[0]
## loading = Label(loadingSplash,text='SirBot')
## loadingSplash.overrideredirect(True)
## loading.pack()
##
## h = loading.winfo_screenheight()
## w = loading.winfo_screenwidth()
##
## loadingSplash.wm_attributes('-alpha',0.75)
## loadingSplash.update_idletasks()
## loadingSplash.geometry('262x112+'+str(int(w/2)-131*1)+
## '+'+str(int(h/2)-56*1))
## loadingSplash.update_idletasks()
## loadingSplash.update()
def destroy(self):
try:
self.loadingSplash.destroy()
except:
#log
pass
def getroot(self):
return(self.root)
示例8: average_normals
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def average_normals( self ):
""" Applies Gouraud normalization to the module
"""
# Set up updater
top = Toplevel()
pb = Progressbar(top,orient ="horizontal",length = 200, mode ="determinate")
pb['maximum'] = len(self.__elements__)
pb['value'] = 10
pb.grid(row=0,column=0)
tx = Label(top)
tx.grid(row=1,column=0)
top.update_idletasks()
top.lift()
t0 = time.time()
# run the loop, if we're visible and phong shading
if not self.invisible == 'gouroud':
try:
buf = np.array([0,0,0,1])
for i,polygon in enumerate(self.__elements__):
if not ispoly(polygon): continue
polygon._onorms = np.array([polygon.normals.astype(float)+buf for i in range(len(polygon.coordinates))])
# Update the user as to what's going on
if i % 50 == 0 and i > 0:
pb['value'] = i
tmp = i/len(self.__elements__)
estimation = int(tmp*(time.time()-t0) * (1-tmp)/tmp)
tx.configure(text=str(int(100*i/len(self.__elements__)))+"%"+' Estimated time: '+str(estimation)+'s' )
top.update_idletasks()
for c,coordinate in enumerate(polygon.coordinates):
for j,opolygon in enumerate(self.__elements__):
if i == j or not ispoly(opolygon): continue
for k,ocoordinate in enumerate(opolygon.coordinates):
if all(coordinate == ocoordinate): # same vertex, finally
polygon._onorms[c] += (opolygon.normals+buf)
polygon._onorms /= polygon._onorms[:,3,None]
for polygon in self.__elements__:
if ispoly(polygon):
polygon.normals = polygon._onorms
del polygon._onorms
except IndexError as ie: pass
top.destroy()
if self.invisible == 'gouroud':
self.invisible = False
return self # for chaining
示例9: ShapesMenu
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
class ShapesMenu(object):
"""
"""
def __init__(self, master, line_collection):
try:
self.width_of_entry = len(line_collection[0])
except IndexError:
self.width_of_entry = 0
self.top = Toplevel(master)
self.current_lines_listbox = Listbox(self.top)
self.removed_lines_listbox = Listbox(self.top)
self.submit = Button(self.top, text = "Ok", command=self.submit)
self.remove_button = Button(self.top, text = "Remove", command=self.remove_line)
self.cancel = Button(self.top, text = "Cancel", command=self.top.destroy)
self.top.bind("<Return>", func=self.submit)
self.current_lines = line_collection
self.removed_lines = []
self.ids_internal = []
self.ids = []
for index, line in enumerate(self.current_lines):
#removes the point data and converts the rest to strings
id = line[1]
if id not in self.ids_internal:
self.ids_internal.append(id)
self.ids.append(id)
line = [str(element) for element in line[1:]]
#put into the list
self.current_lines_listbox.insert(index, " ".join(line))
self.current_lines_listbox.grid(row=0, column=0, columnspan=3)
self.submit.grid(row=1, column=1)
self.cancel.grid(row=1, column=2)
self.remove_button.grid(row=1, column=0)
def submit(self):
#expose the internal IDs to remove to the exterior methods
self.ids = self.ids_internal
self.top.destroy()
def remove_line(self):
"""Take the active line and remove it"""
line_to_remove = self.current_lines_listbox.get(ANCHOR)
id_to_remove = int(line_to_remove.split(" ")[0])
#remove it from the ID list
self.ids_internal.remove(id_to_remove)
#remove it from the listbox
self.current_lines_listbox = self.current_lines_listbox.delete(ANCHOR)
示例10: askgridprop
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def askgridprop():
win = Toplevel()
color = ['#000000', '#000000']
propvars = [StringVar() for i in range(4)]
guidata = (
{
'linestyle': ('Major Line Style', propvars[0], None),
'linewidth': ('Major Line Width', propvars[1], check_nonnegative_float)
},
{
'linestyle': ('Minor Line Style', propvars[2], None),
'linewidth': ('Minor Line Width', propvars[3], check_nonnegative_float)
}
)
for d in guidata:
for key in d:
pitem = LabeledEntry(win)
pitem.pack()
pitem.label_text = d[key][0]
pitem.entry['textvariable'] = d[key][1]
if d[key][2]:
pitem.checker_function = d[key][2]
def setmajorcolor():
c = askcolor()
color[0] = c[1]
def setminorcolor():
c = askcolor()
color[1] = c[1]
Button(win, text='Major Line Color', command=setmajorcolor).pack()
Button(win, text='Minor Line Color', command=setminorcolor).pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
win.destroy()
c_major = StringVar(); c_major.set(color[0])
c_minor = StringVar(); c_minor.set(color[1])
guidata[0]['color'] = ('Major Line Color', c_major, None)
guidata[1]['color'] = ('Minor Line Color', c_minor, None)
return guidata
示例11: ZoomWindow
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [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()
示例12: askSpan
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def askSpan(orient='v'):
win = Toplevel()
pxmin = LabeledEntry(win)
pxmin.pack()
pxmin.label_text = 'xmin' if orient=='v' else 'ymin'
pxmax = LabeledEntry(win)
pxmax.pack()
pxmax.label_text = 'xmax' if orient=='v' else 'ymax'
def formatter(val):
val = float(val)
val /= 100.
return '{0:0.2f}'.format(val)
alphaScale = LabeledScale(win, from_=0, to=100, name='alpha', formatter=formatter)
alphaScale.set(50.0)
alphaScale.pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
xmin = pxmin.entry.get()
xmax = pxmax.entry.get()
alpha = alphaScale.get() / 100.
win.destroy()
return map(float, (xmin, xmax, alpha))
示例13: ask_class_name
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def ask_class_name():
win = Toplevel()
module_name = StringVar()
class_name = StringVar()
module_item = LabeledEntry(win)
module_item.label_text = 'Module Name'
module_item.pack()
module_item.entry_variable = module_name
class_item = LabeledEntry(win)
class_item.label_text = 'Class Name'
class_item.pack()
class_item.entry_variable = class_name
Button(win, text='OK', command=win.quit).pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
win.destroy()
return module_name.get(), class_name.get()
示例14: CFGEditor
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
#.........这里部分代码省略.........
# If there's no arrow at all, highlight the whole line.
start = '%d.0' % linenum
end = '%d.end' % linenum
elif not CFGEditor._LHS_RE.match(line):
# Otherwise, if the LHS is bad, highlight it.
start = '%d.0' % linenum
end = '%d.%d' % (linenum, arrowmatch.start())
else:
# Otherwise, highlight the RHS.
start = '%d.%d' % (linenum, arrowmatch.end())
end = '%d.end' % linenum
# If we're highlighting 0 chars, highlight the whole line.
if self._textwidget.compare(start, '==', end):
start = '%d.0' % linenum
end = '%d.end' % linenum
self._textwidget.tag_add('error', start, end)
def _analyze(self, *e):
"""
Replace ``->`` with arrows, and colorize the entire buffer.
"""
self._replace_arrows()
numlines = int(self._textwidget.index('end').split('.')[0])
for linenum in range(1, numlines+1): # line numbers start at 1.
self._analyze_line(linenum)
def _parse_productions(self):
"""
Parse the current contents of the textwidget buffer, to create
a list of productions.
"""
productions = []
# Get the text, normalize it, and split it into lines.
text = self._textwidget.get('1.0', 'end')
text = re.sub(self.ARROW, '->', text)
text = re.sub('\t', ' ', text)
lines = text.split('\n')
# Convert each line to a CFG production
for line in lines:
line = line.strip()
if line=='': continue
productions += parse_cfg_production(line)
#if line.strip() == '': continue
#if not CFGEditor._PRODUCTION_RE.match(line):
# raise ValueError('Bad production string %r' % line)
#
#(lhs_str, rhs_str) = line.split('->')
#lhs = Nonterminal(lhs_str.strip())
#rhs = []
#def parse_token(match, rhs=rhs):
# token = match.group()
# if token[0] in "'\"": rhs.append(token[1:-1])
# else: rhs.append(Nonterminal(token))
# return ''
#CFGEditor._TOKEN_RE.sub(parse_token, rhs_str)
#
#productions.append(Production(lhs, *rhs))
return productions
def _destroy(self, *e):
if self._top is None: return
self._top.destroy()
self._top = None
def _ok(self, *e):
self._apply()
self._destroy()
def _apply(self, *e):
productions = self._parse_productions()
start = Nonterminal(self._start.get())
cfg = ContextFreeGrammar(start, productions)
if self._set_cfg_callback is not None:
self._set_cfg_callback(cfg)
def _reset(self, *e):
self._textwidget.delete('1.0', 'end')
for production in self._cfg.productions():
self._textwidget.insert('end', '%s\n' % production)
self._analyze()
if self._set_cfg_callback is not None:
self._set_cfg_callback(self._cfg)
def _cancel(self, *e):
try: self._reset()
except: pass
self._destroy()
def _help(self, *e):
# The default font's not very legible; try using 'fixed' instead.
try:
ShowText(self._parent, 'Help: Chart Parser Demo',
(_CFGEditor_HELP).strip(), width=75, font='fixed')
except:
ShowText(self._parent, 'Help: Chart Parser Demo',
(_CFGEditor_HELP).strip(), width=75)
示例15: destroy
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import destroy [as 别名]
def destroy(self): # close win silently
Toplevel.destroy(self) # redef for close ops