本文整理汇总了Python中tkinter.Canvas方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Canvas方法的具体用法?Python tkinter.Canvas怎么用?Python tkinter.Canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.Canvas方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sb_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _sb_canvas(self, root, expand='y',
fill='both', side='bottom'):
"""
Helper for __init__: construct a canvas with a scrollbar.
"""
cframe =tkinter.Frame(root, relief='sunk', border=2)
cframe.pack(fill=fill, expand=expand, side=side)
canvas = tkinter.Canvas(cframe, background='#e0e0e0')
# Give the canvas a scrollbar.
sb = tkinter.Scrollbar(cframe, orient='vertical')
sb.pack(side='right', fill='y')
canvas.pack(side='left', fill=fill, expand='yes')
# Connect the scrollbars to the canvas.
sb['command']= canvas.yview
canvas['yscrollcommand'] = sb.set
return (sb, canvas)
示例2: show_friends
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def show_friends(self):
self.configure(menu=self.menu)
self.login_frame.pack_forget()
self.canvas = tk.Canvas(self, bg="white")
self.canvas_frame = tk.Frame(self.canvas)
self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.scrollbar.set)
self.scrollbar.pack(side=tk.LEFT, fill=tk.Y)
self.canvas.pack(side=tk.LEFT, expand=1, fill=tk.BOTH)
self.friends_area = self.canvas.create_window((0, 0), window=self.canvas_frame, anchor="nw")
self.bind_events()
self.load_friends()
示例3: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def __init__(self):
root = tk.Tk()
# show no frame
root.overrideredirect(True)
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (self.width / 2)
y = (hs / 2) - (self.height / 2)
root.geometry('%dx%d+%d+%d' % (self.width, self.height, x, y))
image = tk.PhotoImage(file=self.image_file)
canvas = tk.Canvas(root, height=self.height, width=self.width, bg="brown")
canvas.create_image(self.width/2, self.height/2, image=image)
canvas.pack()
root.after(2500, root.destroy)
root.mainloop()
示例4: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def __init__(self, host_canvas, data, node_name):
tk.Canvas.__init__(self, width=20, height=20, highlightthickness=0)
self._host_canvas = host_canvas
self._complete = True
self._marked = False
self._default_bg = None
self.bind('<ButtonPress-1>', self._host_event('onNodeButtonPress'))
self.bind('<ButtonRelease-1>', self._host_event('onNodeButtonRelease'))
self.bind('<B1-Motion>', self._host_event('onNodeMotion'))
self.bind('<Button-3>', self._host_event('onTokenRightClick'))
self.bind('<Key>', self._host_event('onNodeKey'))
self.bind('<Enter>', lambda e: self.focus_set())
self.bind('<Leave>', lambda e: self.master.focus())
# Draw myself
self.render(data, node_name)
示例5: _plot_graph
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _plot_graph(self, graph):
# Create nodes
scale = min(self.winfo_width(), self.winfo_height())
if scale == 1:
# Canvas not initilized yet; use height and width hints
scale = int(min(self['width'], self['height']))
scale -= 50
if len(graph) > 1:
layout = self.create_layout(graph, scale=scale, min_distance=50)
# Find min distance between any node and make sure that is at least
# as big as
for n in graph.nodes():
self._draw_node(layout[n]+20, n)
else:
self._draw_node((scale/2, scale/2), graph.nodes()[0])
# Create edges
for frm, to in set(graph.edges()):
self._draw_edge(frm, to)
self._graph_changed()
示例6: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def __init__(self, parent, property_dict, *args, **kw):
tk.Frame.__init__(self, parent, *args, **kw)
# create a canvas object and a vertical scrollbar for scrolling it
self.vscrollbar = vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
vscrollbar.pack(fill=tk.Y, side=tk.RIGHT, expand=tk.FALSE)
self.canvas = canvas = tk.Canvas(self, bd=0, highlightthickness=0,
yscrollcommand=vscrollbar.set)
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.TRUE)
vscrollbar.config(command=canvas.yview)
# reset the view
canvas.xview_moveto(0)
canvas.yview_moveto(0)
# create a frame inside the canvas which will be scrolled with it
self.interior = interior = tk.Frame(canvas)
self.interior_id = canvas.create_window(0, 0, window=interior,
anchor='nw')
self.interior.bind('<Configure>', self._configure_interior)
self.canvas.bind('<Configure>', self._configure_canvas)
self.build(property_dict)
示例7: ui
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def ui():
root = tkinter.Tk()
root.title('PDF和照片互转器') # 标题
root.resizable(width=False, height=False) # 防止大小调整
canvas = tkinter.Canvas(root, width=450, height=320, highlightthickness=0) # 创建画布
photo = tkinter.PhotoImage(file=file_zip_path + os.sep + 'pdf.png') # 获取背景图片的网络连接
canvas.create_image(225, 160, image=photo)
select_dir_button = tkinter.Button(root, text="选择照片文件夹", command=select_dir, bg='yellow') # 创建按钮
select_pdf_button = tkinter.Button(root, text="选择PDF文件", command=select_pdf, bg='green')
click_button = tkinter.Button(root, text="点击执行", command=start, bg='blue')
select_dir_button.pack() # 启动按钮
select_pdf_button.pack()
click_button.pack()
canvas.create_window(240, 120, width=100, height=30, window=select_dir_button) # 将按钮创建到画布
canvas.create_window(240, 190, width=100, height=30, window=select_pdf_button)
canvas.create_window(240, 260, width=100, height=30, window=click_button)
canvas.pack() # 启动画布
root.mainloop() # 主程序循环
示例8: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# 그리드 생성
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
# 캔버스에 이미지 추가
self.rectangle = canvas.create_image(50, 50, image=self.shapes[0])
self.triangle1 = canvas.create_image(250, 150, image=self.shapes[1])
self.triangle2 = canvas.create_image(150, 250, image=self.shapes[1])
self.circle = canvas.create_image(250, 250, image=self.shapes[2])
canvas.pack()
return canvas
示例9: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# 그리드 생성
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
self.rewards = []
self.goal = []
# 캔버스에 이미지 추가
x, y = UNIT/2, UNIT/2
self.rectangle = canvas.create_image(x, y, image=self.shapes[0])
canvas.pack()
return canvas
示例10: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# 그리드 생성
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
# 캔버스에 이미지 추가
self.rectangle = canvas.create_image(50, 50, image=self.shapes[0])
self.triangle1 = canvas.create_image(250, 150, image=self.shapes[1])
self.triangle2 = canvas.create_image(150, 250, image=self.shapes[1])
self.circle = canvas.create_image(250, 250, image=self.shapes[2])
canvas.pack()
return canvas
示例11: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def __init__(self):
self.root = tkinter.Tk()
self.root.title("Mandelbrot (Pyro multi CPU core version)")
canvas = tkinter.Canvas(self.root, width=res_x, height=res_y, bg="#000000")
canvas.pack()
self.img = tkinter.PhotoImage(width=res_x, height=res_y)
canvas.create_image((res_x/2, res_y/2), image=self.img, state="normal")
with locate_ns() as ns:
mandels = ns.yplookup(meta_any={"class:mandelbrot_calc_color"})
mandels = list(mandels.items())
print("{0} mandelbrot calculation servers found.".format(len(mandels)))
if not mandels:
raise ValueError("launch at least one mandelbrot calculation server before starting this")
self.mandels = [uri for _, (uri, meta) in mandels]
self.pool = futures.ThreadPoolExecutor(max_workers=len(self.mandels))
self.tasks = []
self.start_time = time.time()
for line in range(res_y):
self.tasks.append(self.calc_new_line(line))
self.root.after(100, self.draw_results)
tkinter.mainloop()
示例12: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# create grids
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
# add img to canvas
self.rectangle = canvas.create_image(50, 50, image=self.shapes[0])
self.triangle1 = canvas.create_image(250, 150, image=self.shapes[1])
self.triangle2 = canvas.create_image(150, 250, image=self.shapes[1])
self.circle = canvas.create_image(250, 250, image=self.shapes[2])
# pack all
canvas.pack()
return canvas
示例13: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# create grids
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
self.rewards = []
self.goal = []
# add image to canvas
x, y = UNIT/2, UNIT/2
self.rectangle = canvas.create_image(x, y, image=self.shapes[0])
# pack all`
canvas.pack()
return canvas
示例14: _build_canvas
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def _build_canvas(self):
canvas = tk.Canvas(self, bg='white',
height=HEIGHT * UNIT,
width=WIDTH * UNIT)
# create grids
for c in range(0, WIDTH * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = c, 0, c, HEIGHT * UNIT
canvas.create_line(x0, y0, x1, y1)
for r in range(0, HEIGHT * UNIT, UNIT): # 0~400 by 80
x0, y0, x1, y1 = 0, r, HEIGHT * UNIT, r
canvas.create_line(x0, y0, x1, y1)
# add img to canvas
self.rectangle = canvas.create_image(50, 50, image=self.shapes[0])
self.triangle1 = canvas.create_image(250, 150, image=self.shapes[1])
self.triangle2 = canvas.create_image(150, 250, image=self.shapes[1])
self.circle = canvas.create_image(250, 250, image=self.shapes[2])
# pack all
canvas.pack()
return canvas
示例15: addQuitButton
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Canvas [as 别名]
def addQuitButton(self):
""" draws and places the quit icon on the main window """
self.quitButton = tk.Canvas(width=15, height=15, background="black",
highlightbackground="white", highlightthickness="1")
self.quitButton.create_line(0,0,16,16,fill="white")
self.quitButton.create_line(1,15,16,0,fill="white")
self.quitButton.grid(row="5", column="19", sticky="ne")
self.quitButton.bind("<ButtonPress-1>", self.buttonDimGray)
self.quitButton.bind("<ButtonRelease-1>", self.quitEvent)
self.quitButton.bind("<Enter>", self.buttonGray25)
self.quitButton.bind("<Leave>", self.buttonBlack)
tk.Frame(self, height=1, width=5, background="black").grid(row="5", column="18")
self.rightSpacerFrame = tk.Frame(width=5, height=5, background="black")
self.rightSpacerFrame.grid(row="0", column="100", rowspan="50")
self.rightSpacerFrame.grid_remove()