本文整理汇总了Python中tkinter.Canvas.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.destroy方法的具体用法?Python Canvas.destroy怎么用?Python Canvas.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.destroy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mjolnir
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import destroy [as 别名]
class Mjolnir(KRCCModule):
def __init__(self, root):
super().__init__()
self.canvas = Canvas(root)
self.canvas.pack(side=RIGHT, fill=BOTH, expand=True)
self.canvas.configure(background='#000000')
def __del__(self):
self.canvas.destroy()
def run(self):
while not self.terminate:
pass
def name(self):
return 'Mjolnir'
示例2: Tenacity2
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import destroy [as 别名]
class Tenacity2(KRCCModule):
def __init__(self, root):
super().__init__()
self.arbitrary_list = [
('bla', random.uniform(0, 500)),
('blub', random.randint(1, 10)),
('hurrz', 'yolo'),
'sploink',
]
self.listbox = Listbox(root)
self.canvas = Canvas(root)
self.load()
def __del__(self):
self.canvas.destroy()
self.listbox.destroy()
def run(self):
while not self.terminate:
pass
def name(self):
return 'Tenacity 2'
def load(self):
for item in self.arbitrary_list:
insert_item = 'error'
if type(item) == type(''):
insert_item = item
elif type(item) == type(()):
key = item[0]
value = '%s' % item[1]
if type(item[1]) == float:
value = '%8.3f' % item[1]
insert_item = '%s: %s' % (key, value)
self.listbox.insert(END, insert_item)
self.listbox.pack(side=LEFT, fill=Y)
self.canvas.pack(side=RIGHT, fill=BOTH, expand=True)
示例3: CanvasRenderer
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import destroy [as 别名]
#.........这里部分代码省略.........
for sprite in self.path_sprites:
self.canvas.delete(sprite)
self.path_sprites.clear()
if 'nonogram' in kwargs and kwargs['nonogram'] is not None:
p = path[0].state
for y in range(kwargs['nonogram'].total_rows):
if len(p.nodes[y]) != 1:
continue
for x in range(len(p.nodes[y][0][1])):
coords = (
x * BOARD_CELL_SIZE + 1,
y * BOARD_CELL_SIZE + 1,
x * BOARD_CELL_SIZE + BOARD_CELL_SIZE + 1,
y * BOARD_CELL_SIZE + BOARD_CELL_SIZE + 1
)
fill_color = '#FFFFFF'
if p.nodes[y][0][1][x]:
fill_color = '#22EE22'
# Create sprite and add to path sprite cache
self.path_sprites.add(
self.canvas.create_rectangle(
*coords,
fill=fill_color
)
)
self.window.master.controller.references['path_length'].set(
'Path length: %d' % (len(path) - 1)
)
self.window.master.controller.references['open_set_size'].set(
'OpenSet size: %d' % open_set
)
self.window.master.controller.references['closed_set_size'].set(
'ClosedSet size: %d' % (closed_set - 1)
)
self.window.master.controller.references['total_set_size'].set(
'Total set size: %d' % (open_set + closed_set - 1)
)
else:
# Add sprites for current path
for node in reversed(path[:-1]):
# If we are drawing using mathematical coordinates (y-reversed)
y = node.y
if math_coords:
y = self.board_height - node.y
# Create the coordinates and dimension tuple
coords = (
node.x * BOARD_CELL_SIZE + 1,
y * BOARD_CELL_SIZE + 1,
node.x * BOARD_CELL_SIZE + BOARD_CELL_SIZE + 1,
y * BOARD_CELL_SIZE + BOARD_CELL_SIZE + 1
)
fill_color = '#994499'
# Create sprite and add to path sprite cache
self.path_sprites.add(
self.canvas.create_rectangle(
*coords,
fill=fill_color
)
)
self.window.master.controller.references['path_length'].set(
'Path length: %d' % (len(path) - 1)
)
self.window.master.controller.references['open_set_size'].set(
'OpenSet size: %d' % open_set
)
self.window.master.controller.references['closed_set_size'].set(
'ClosedSet size: %d' % closed_set
)
self.window.master.controller.references['total_set_size'].set(
'Total set size: %d' % (open_set + closed_set)
)
def clear(self):
"""
Clears the content area
"""
self.canvas.delete('all')
self.window.master.controller.clear_timers()
self.window.master.controller.clear_stats()
def destruct(self):
"""
Destroys this canvas
"""
self.window.master.controller.clear_timers()
self.window.master.controller.clear_stats()
self.canvas.destroy()
示例4: mainGUI
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import destroy [as 别名]
class mainGUI(Frame, bootloader, GuiController):
""" Contains the main view for the application """
def __init__(self):
""" Create the initial application GUI environment (tool bars, and other static elements) """
Frame.__init__(self, self.root)
self.thread_entry_field = '' # Hold both search string, and drives autoRefresh logic
self.menuBar = Menu()
self.fileMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="File", menu=self.fileMenu, underline=1)
self.fileMenu.add_command(label="Quit", command=self.root.destroy, underline=1)
self.optionsMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Options", menu=self.optionsMenu)
self.optionsMenu.add_command(label="Settings", command=self.editSettings, underline=1)
self.helpMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Help", menu=self.helpMenu)
self.helpMenu.add_command(label="Help", command=self.program_help, underline=1)
self.helpMenu.add_command(label="About", command=self.program_about, underline=1)
self.master.config(menu=self.menuBar)
self.topFrame = Frame()
self.thread_entry_box = Entry(self.topFrame)
self.thread_entry_box.insert(0, self.DEFAULT_THREAD_TEXT)
self.thread_entry_box.bind('<Return>', lambda event: self.add_thread_GUI())
# Bind needs to send the event to the handler
self.thread_entry_box.pack(side='left', fill='x', expand='True', padx=5)
self.add_thread_btn = Button(self.topFrame)
self.add_thread_btn['text'] = 'Add New Thread'
self.add_thread_btn['command'] = lambda: self.add_thread_GUI()
self.add_thread_btn.pack(side='left', padx=0)
self.topFrame.pack(fill='x')
self.create_thread_frame()
def create_thread_frame(self):
""" Sets up the main thread frame (where the magic happens) """
# Sets up frame
self.thread_list_canvas = Canvas(self.root, borderwidth=0)
self.thread_list_frame = Frame(self.thread_list_canvas)
# Creates scroll bar
self.vsb = Scrollbar(self.root, orient="vertical", command=self.thread_list_canvas.yview)
self.thread_list_canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.hsb = Scrollbar(self.root, orient="horizontal", command=self.thread_list_canvas.xview)
self.thread_list_canvas.configure(xscrollcommand=self.hsb.set)
self.hsb.pack(side="bottom", fill="x")
# Packs frame
self.thread_list_canvas.pack(side="left", fill="both", expand=True)
self.thread_list_canvas.create_window((4, 4), window=self.thread_list_frame, anchor="nw", tags="self.frame")
self.thread_list_frame.bind("<Configure>", self.OnFrameConfigure)
self.create_thread_list_box()
def OnFrameConfigure(self, event):
"""Reset the scroll region to encompass the inner frame"""
self.thread_list_canvas.configure(scrollregion=self.thread_list_canvas.bbox("all"))
# noinspection PyAttributeOutsideInit
def create_thread_list_box(self):
""" Creates the message list box for the create method """
def hover_on(widget):
widget['fg'] = 'dark blue'
# widget['underline'] = True
def hover_off(widget):
widget['fg'] = 'black'
# widget['underline'] = False
for individual_thread in self.MESSAGE_THREADS: # Fetch Message List from model
if individual_thread.is_valid_thread():
self.bg_color = 'green'
else:
self.bg_color = 'red'
self.individual_thread_frame = Frame(self.thread_list_frame,
bg=self.bg_color) # Create frame for each thread
rowToInsertAt = self.MESSAGE_THREADS.index(individual_thread)
self.text_color = 'black'
self.threadText = Label(self.individual_thread_frame, bg=self.bg_color, fg=self.text_color)
self.threadText['text'] = "[ Thread #: " + individual_thread.threadId + " ]"
self.threadText.bind("<Enter>", lambda event, text=self.threadText: hover_on(text))
self.threadText.bind("<Leave>", lambda event, text=self.threadText: hover_off(text))
self.threadText.bind("<Button-1>",
lambda event, thread_in=individual_thread: self.open_in_web_browser(thread_in))
self.threadText.grid(column=0, row=0, sticky='w', padx=0)
#.........这里部分代码省略.........