本文整理汇总了Python中Tkinter.Tk.wm_protocol方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.wm_protocol方法的具体用法?Python Tk.wm_protocol怎么用?Python Tk.wm_protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Tk
的用法示例。
在下文中一共展示了Tk.wm_protocol方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main():
# helper method used when quitting program
def kill_all_threads():
if input_frame.backend_call is not None:
input_frame.backend_call.stop()
input_frame.backend_call.join()
root.destroy()
root = Tk()
root.wm_protocol ("WM_DELETE_WINDOW", kill_all_threads)
root.wm_title("Seating Chart Creator")
centered_window = Frame(root)
centered_window.pack()
header_frame = HeaderFrame(centered_window)
header_frame.grid(row=0, column=0, columnspan=3, sticky=(W))
instructions_frame = InstructionsFrame(centered_window)
instructions_frame.grid(row=1, column=0, columnspan=3, padx=(0,20))
progress_frame = ProgressFrame(centered_window)
progress_frame.grid(row=2, column=1, padx=10, pady=20, sticky=(N))
results_frame = ResultsFrame(centered_window, progress_frame.plot_frame)
results_frame.grid(row=2, column=2, padx=10, sticky=(N))
input_frame = InputFrame(centered_window, progress_frame, results_frame)
input_frame.grid(row=2, column=0, padx=(30,20), sticky=(N))
progress_frame.input_frame = input_frame
results_frame.input_frame = input_frame
root.mainloop()
示例2: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main():
class Tracer(Delegator):
def __init__(self, name):
self.name = name
Delegator.__init__(self, None)
def insert(self, *args):
print self.name, ": insert", args
self.delegate.insert(*args)
def delete(self, *args):
print self.name, ": delete", args
self.delegate.delete(*args)
root = Tk()
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
text = Text()
text.pack()
text.focus_set()
p = Percolator(text)
t1 = Tracer("t1")
t2 = Tracer("t2")
p.insertfilter(t1)
p.insertfilter(t2)
root.mainloop()
p.removefilter(t2)
root.mainloop()
p.insertfilter(t2)
p.removefilter(t1)
root.mainloop()
示例3: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main(argv=None):
end = False
rulesFile = None
outDir = "GenCode"
if argv is None:
argv = sys.argv
for arg in argv:
if arg.startswith('-rulesFile='):
rulesFile = arg[11:]
elif arg.startswith('-outDir='):
outDir = arg[8:]
elif arg.startswith('-?'):
print "python GenPyCode.py [OPTIONS]"
print " -? Options Help"
print " -rulesFile= Name of the rules file to use as input"
print " -outDir= Output directory of generated code"
end = True
if end:
return 0
root = Tk()
gui = GuiFrame(root, rulesFile, outDir)
root.wm_protocol ("WM_DELETE_WINDOW", gui.gui_exit)
while not gui.exit:
root.update()
time.sleep(.1)
return (0)
示例4: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main():
from Tkinter import Tk, Text
from Percolator import Percolator
root = Tk()
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
text = Text()
text.pack()
text.focus_set()
p = Percolator(text)
d = UndoDelegator()
p.insertfilter(d)
root.mainloop()
示例5: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main():
from Tkinter import Tk, Text
from Percolator import Percolator
root = Tk()
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
text = Text(background="white")
text.pack(expand=1, fill="both")
text.focus_set()
p = Percolator(text)
d = ColorDelegator()
p.insertfilter(d)
root.mainloop()
示例6: TkMonitor
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
class TkMonitor(Monitor):
"""
An interface over a dictionary {taskno: scrolledtext widget}, with
methods add_listener, del_listener, notify_listener and start/stop.
"""
def __init__(self, name, queue=None):
Monitor.__init__(self, name, queue)
self.widgets = {}
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def add_listener(self, taskno):
"There is a ScrolledText for each task"
st = ScrolledText(self.root, height=5)
st.insert('end', 'Output of task %d\n' % taskno)
st.pack()
self.widgets[taskno] = st
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def del_listener(self, taskno):
del self.widgets[taskno]
@plac_core.annotations(taskno=('task number', 'positional', None, int))
def notify_listener(self, taskno, msg):
w = self.widgets[taskno]
w.insert('end', msg + '\n')
w.update()
def start(self):
'Start the mainloop'
self.root = Tk()
self.root.title(self.name)
self.root.wm_protocol("WM_DELETE_WINDOW", self.stop)
self.root.after(0, self.read_queue)
try:
self.root.mainloop()
except KeyboardInterrupt:
print >> sys.stderr, 'Process %d killed by CTRL-C' % os.getpid()
except TerminatedProcess:
pass
def stop(self):
self.root.quit()
def read_queue(self):
try:
cmd_args = self.queue.get_nowait()
except Queue.Empty:
pass
else:
getattr(self, cmd_args[0])(*cmd_args[1:])
self.root.after(100, self.read_queue)
示例7: main
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def main():
from Tkinter import Tk, Text
root = Tk()
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
text = Text()
text.pack()
text.focus_set()
redir = WidgetRedirector(text)
global previous_tcl_fcn
def my_insert(*args):
print "insert", args
previous_tcl_fcn(*args)
previous_tcl_fcn = redir.register("insert", my_insert)
root.mainloop()
redir.unregister("insert") # runs after first 'close window'
redir.close()
root.mainloop()
root.destroy()
示例8: test
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import wm_protocol [as 别名]
def test():
app = Tk()
app.wm_title("CropGUI -- lossless cropping and rotation of jpeg files")
app.wm_iconname("CropGUI")
preview = Label(app)
do_crop = Button(app, text="Crop")
info = Label(app)
preview.pack(side="bottom")
do_crop.pack(side="left")
info.pack(side="left")
max_h = app.winfo_screenheight() - 64 - 32
max_w = app.winfo_screenwidth() - 64
drag = DragManager(app, preview, do_crop, info)
app.wm_protocol('WM_DELETE_WINDOW', drag.close)
def image_names():
if len(sys.argv) > 1:
for i in sys.argv[1:]:
yield i
else:
while 1:
names = askopenfilename(
master=app,
defaultextension=".jpg", multiple=1, parent=app,
filetypes=(
("JPEG Image Files", ".jpg .JPG .jpeg .JPEG"),
("All files", "*"),
),
title="Select images to crop")
if not names:
break
for name in names:
yield name
pids = set()
def reap():
global pids
pids = set(p for p in pids if p.poll() is None)
for image_name in image_names():
img = Image.open(image_name)
iw, ih = img.size
scale = 1
while iw > max_w or ih > max_h:
iw /= 2
ih /= 2
scale *= 2
img.thumbnail((iw, ih))
drag.image = img
drag.round = max(1, 8/scale)
if not drag.wait():
continue # user hit "next" (tba) without cropping
base, ext = os.path.splitext(image_name)
t, l, r, b = drag.top, drag.left, drag.right, drag.bottom
t *= scale
l *= scale
r *= scale
b *= scale
cropspec = "%dx%d+%d+%d" % (r-l, b-t, l, t)
target = base + "-crop" + ext
target = open(target, "wb")
pids.add(subprocess.Popen(
['jpegtran', '-optimize', '-progressive', '-crop', cropspec, image_name],
stdout=target))
target.close()
while pids:
reap()
sys.stdout.write("Waiting for %d children to exit. \r" % len(pids))
sys.stdout.flush()
time.sleep(.1)
sys.stdout.write(" "*79 + "\r")