本文整理汇总了Python中tkinter.Toplevel.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python Toplevel.protocol方法的具体用法?Python Toplevel.protocol怎么用?Python Toplevel.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Toplevel
的用法示例。
在下文中一共展示了Toplevel.protocol方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ToplevelVidget
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [as 别名]
class ToplevelVidget(object):
"""
ToplevelVidget contains a Toplevel widget.
"""
def __init__(
self,
close_handler=None,
master=None,
):
"""
Initialize object.
@param close_handler: Window close button event handler.
@param master: Master widget.
@return: None.
"""
# Create toplevel widget
self._toplevel = Toplevel(master=master)
# Hide the toplevel widget
self._toplevel.withdraw()
# Window close button event handler
self._close_handler = close_handler \
if close_handler is not None else self._close_handler_default
# Register window close button event handler
self._toplevel.protocol('WM_DELETE_WINDOW', self._close_handler)
def toplevel(self):
"""
Get the toplevel widget.
@return: toplevel widget.
"""
return self._toplevel
def __getattr__(self, name):
"""
Delegate attribute lookup to the toplevel widget.
@return: Attribute value, or raise AttributeError.
"""
return getattr(self._toplevel, name)
def _close_handler_default(self):
"""
Default window close button event handler.
@return: None.
"""
# Hide the toplevel widget
self._toplevel.withdraw()
# Release grab on the toplevel widget
self._toplevel.grab_release()
示例2: receivePrivateChat
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [as 别名]
def receivePrivateChat(self, connectingUser):
global conversationBoxList
print("CHAT PRIVATA in arrivo con "+connectingUser)
newWindow = Toplevel(self.parent)
newWindow.title("Python Chat requested by "+connectingUser)
newWindow.minsize(400, 475)
newWindow.focus()
def disconnectPM():
del conversationBoxList[connectingUser]
newWindow.destroy()
newWindow.protocol('WM_DELETE_WINDOW', disconnectPM)
#label = Label(newWindow, text="PROVA PROVA")
#label.pack(side="top", fill="both", padx=10, pady=10)
frame = Frame(newWindow)
frame.pack(fill=BOTH, expand=1, side=LEFT)
box = ScrolledText(frame, wrap=WORD, relief = GROOVE, width=30, height=18, font=self.customFontMessage)
box.config(state=DISABLED)
box.pack(expand="yes", fill=BOTH, side=TOP)
textarea = Text(frame, width=30, height=5)
textarea.bind("<KeyRelease-Return>", lambda event : self.getprivatetext(event, textarea, connectingUser))
textarea.pack(expand="yes", fill=BOTH, side=TOP)
#aggiungo alla mappa globale il box di conversazione
conversationBoxList[connectingUser] = box
示例3: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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()
示例4: draw_window
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [as 别名]
def draw_window(self):
window = Toplevel(self)
title = string.capwords(self.phrase.replace('_', ' '))
window.wm_title('Notes on: ' + title)
window.protocol('WM_DELETE_WINDOW', self.save_note)
text = Text(window, name="note")
text.grid(row=0, column=0)
return window
示例5: TkWindowNode
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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)
示例6: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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: askgridprop
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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
示例8: create_widgets
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [as 别名]
def create_widgets(self):
'''Create basic 3 row x 3 col search (find) dialog.
Other dialogs override subsidiary create_x methods as needed.
Replace and Find-in-Files add another entry row.
'''
top = Toplevel(self.root)
top.bind("<Return>", self.default_command)
top.bind("<Escape>", self.close)
top.protocol("WM_DELETE_WINDOW", self.close)
top.wm_title(self.title)
top.wm_iconname(self.icon)
self.top = top
self.row = 0
self.top.grid_columnconfigure(0, pad=2, weight=0)
self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
self.create_entries() # row 0 (and maybe 1), cols 0, 1
self.create_option_buttons() # next row, cols 0, 1
self.create_other_buttons() # next row, cols 0, 1
self.create_command_buttons() # col 2, all rows
示例9: _license
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [as 别名]
def _license(self):
""" affiche la licence dans une nouvelle fenêtre """
def close():
""" ferme la fenêtre """
self.focus_set()
fen.destroy()
fen = Toplevel(self)
fen.title(_("License"))
fen.transient(self)
fen.protocol("WM_DELETE_WINDOW", close)
fen.resizable(0, 0)
fen.grab_set()
# set_icon(fen)
texte = Text(fen, width=50, height=18)
texte.pack()
texte.insert("end",
_("Sudoku-Tk is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\n"))
texte.insert("end",
_("Sudoku-Tk is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\n"))
texte.insert("end",
_("You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/."))
i = int(texte.index("5.end").split(".")[1])
texte.tag_add("link", "5.%i" % (i - 29), "5.%i" % (i - 1))
texte.tag_configure("link", foreground="#0000ff", underline=1)
texte.tag_bind("link", "<Button - 1>",
lambda event: webOpen("http://www.gnu.org/licenses/"))
texte.tag_bind("link", "<Enter>",
lambda event: texte.config(cursor="hand1"))
texte.tag_bind("link",
"<Leave>", lambda event: texte.config(cursor=""))
texte.configure(state="disabled", wrap="word")
b_close = Button(fen, text=_("Close"), command=close)
b_close.pack(side="bottom")
b_close.focus_set()
fen.wait_window(fen)
示例10: ask_class_name
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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()
示例11: askSpan
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import protocol [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))