本文整理汇总了Python中tkinter.Canvas类的典型用法代码示例。如果您正苦于以下问题:Python Canvas类的具体用法?Python Canvas怎么用?Python Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Canvas类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
'''runs the program'''
square_width = 64
num_cols = 7
num_rows = 6
canvas_width = (num_cols+1)*square_width
canvas_height = (num_rows+1)*square_width
window = Tk()
window.configure(background='black')
window.title("DynaBLASTER")
window.resizable(0,0) #removes maximize option
#window.iconbitmap('icon.ico')
#window.tk.call('tk', 'scaling', 20.0)
canvas = Canvas(window, width=canvas_width, highlightthickness=0,
height=canvas_height, background='#717171')
canvas.grid(row=1,column=0, columnspan=5)
graphics = Graphics(canvas, num_rows, num_cols, square_width, window)
board = Board(canvas, square_width, num_rows, num_cols,
canvas_width, canvas_height)
col=0
row=0
player1 = Player(canvas, board, square_width, graphics, col, row)
col = graphics.cols - 3
row = graphics.rows - 3
player2 = Player(canvas, board, square_width, graphics, col, row)
# Import settings from bindings file
bindings_file = open('bindings.json')
p1_bindings, p2_bindings, gen_bindings = json.load(bindings_file)
window.bind(key_release_of(p1_bindings["Up"]), lambda event:player1.key_release('Up'))
window.bind(key_release_of(p1_bindings["Down"]), lambda event:player1.key_release('Down'))
window.bind(key_release_of(p1_bindings["Left"]), lambda event:player1.key_release('Left'))
window.bind(key_release_of(p1_bindings["Right"]), lambda event:player1.key_release('Right'))
window.bind(p1_bindings["Up"], lambda event:player1.key_press('Up'))
window.bind(p1_bindings["Down"],lambda event:player1.key_press('Down'))
window.bind(p1_bindings["Left"], lambda event:player1.key_press('Left'))
window.bind(p1_bindings["Right"], lambda event:player1.key_press('Right'))
window.bind(p1_bindings["Bomb"], player1.place_bomb)
window.bind(key_release_of(p2_bindings["Up"]), lambda event:player2.key_release('Up'))
window.bind(key_release_of(p2_bindings["Down"]), lambda event:player2.key_release('Down'))
window.bind(key_release_of(p2_bindings["Left"]), lambda event:player2.key_release('Left'))
window.bind(key_release_of(p2_bindings["Right"]), lambda event:player2.key_release('Right'))
window.bind(p2_bindings["Up"], lambda event:player2.key_press('Up'))
window.bind(p2_bindings["Down"], lambda event:player2.key_press('Down'))
window.bind(p2_bindings["Left"], lambda event:player2.key_press('Left'))
window.bind(p2_bindings["Right"], lambda event:player2.key_press('Right'))
window.bind(p2_bindings["Bomb"], player2.place_bomb)
window.bind(gen_bindings["Pause"], lambda event:pause_game(player1, player2, graphics))
window.mainloop()
开发者ID:abel465,项目名称:DynaBLASTER,代码行数:56,代码来源:DynaBLASTER.py
示例2: clear_can
def clear_can():
"""
캔버스를 초기화 하는 버튼명령
"""
global can, tx_counter, count
can.destroy()
can = Canvas(frame_left, width=400, height=400, bg="#FFFFFF")
tx_counter = can.create_text(20, 10, text="0")
can.pack()
count = 0
开发者ID:soma0sd,项目名称:python-study,代码行数:10,代码来源:03_button.py
示例3: __init__
def __init__(self, parent):
Canvas.__init__(self, width=WIDTH, height=HEIGHT,
background="black", highlightthickness=0)
self.parent = parent
self.initGame()
self.pack()
开发者ID:gddickinson,项目名称:python_code,代码行数:7,代码来源:nibblesGame.py
示例4: initUI
def initUI(self):
self.parent.title("Mario's Picross Puzzle Editor")
self.puzzles = None
# Build the menu
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar)
self.fileMenu = fileMenu
fileMenu.add_command(label="Open Mario's Picross ROM...",
command=self.onOpen)
fileMenu.add_command(label="Save ROM as...",
command=self.onSave,
state=DISABLED)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
# Navigation
Label(self.parent).grid(row=0, column=0)
Label(self.parent).grid(row=0, column=4)
self.parent.grid_columnconfigure(0, weight=1)
self.parent.grid_columnconfigure(4, weight=1)
prevButton = Button(self.parent,
text="<--",
command=self.onPrev,
state=DISABLED
)
self.prevButton = prevButton
prevButton.grid(row=0, column=1)
puzzle_number = 1
self.puzzle_number = puzzle_number
puzzleNumber = Label(self.parent, text="Puzzle #{}".format(puzzle_number))
self.puzzleNumber = puzzleNumber
puzzleNumber.grid(row=0, column=2)
nextButton = Button(self.parent,
text="-->",
command=self.onNext,
state=DISABLED
)
self.nextButton = nextButton
nextButton.grid(row=0, column=3)
# Canvas
canvas = Canvas(self.parent)
self.canvas = canvas
for i in range(15):
for j in range(15):
fillcolor = "gray80"
self.canvas.create_rectangle(10+20*j, 10+20*i,
10+20*(j+1), 10+20*(i+1),
fill=fillcolor,
tags="{},{}".format(i, j)
)
self.canvas.bind("<ButtonPress-1>", self.onClick)
canvas.grid(row=1, columnspan=5, sticky=W+E+N+S)
self.parent.grid_rowconfigure(1, weight=1)
开发者ID:sopoforic,项目名称:cgrr-mariospicross,代码行数:60,代码来源:marios_picross_puzzle_editor_gui.py
示例5: TkWindowMainLoop
class TkWindowMainLoop(Thread):
'''class for thread that handles Tk window creation and main loop'''
def __init__(self, client):
Thread.__init__(self)
self.window = None
self.canvas = None
self.client = client
self.start()
def callbackDeleteWindow(self):
self.client.stop()
def stop(self):
self.window.quit()
def run(self):
self.window = Tk()
self.canvas = Canvas(self.window, width=1024, height=768)
self.canvas.pack()
self.window.protocol("WM_DELETE_WINDOW", self.callbackDeleteWindow)
self.window.mainloop()
def getWindow(self):
return self.window
def getCanvas(self):
return self.canvas
开发者ID:IwfY,项目名称:TkStein3d,代码行数:34,代码来源:tkwindowmainloop.py
示例6: main
def main():
# Basic starter code.
window = tkinter.Tk()
canvas = Canvas(window, width = CANVAS_SIZE, height = CANVAS_SIZE)
canvas.pack()
draw_shaky_line(canvas, 50, 50, 650, 650)
开发者ID:minsun09,项目名称:volo_mission,代码行数:7,代码来源:mapline.py
示例7: __init__
def __init__(self, *args, **kwargs):
Canvas.__init__(self, *args, **kwargs)
self.graphs = []
self.x = Axis()
self.y = Axis()
self.y.direction = -1
self.bind("<Configure>", lambda ev: self.after_idle(self.__onConfigure__))
开发者ID:basilevs,项目名称:varfill,代码行数:7,代码来源:gui.py
示例8: Main
class Main(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.info = {}
self.window = None
self.size = (640, 480)
self.fields = []
self.init_ui()
def init_ui(self):
self.parent.title("Node Writer")
self.style = Style()
self.style.theme_use("alt")
self.pack(fill="both", expand=True)
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
menubar.add_command(label="New", command=self.onNew)
menubar.add_command(label="Show Info", command=self.get_info)
menubar.add_command(label="Exit", command=self.quit)
self.canvas = Canvas(self, background="white", width=self.size[0], height=self.size[1])
self.canvas.pack(fill="both", expand=1)
self.canvas.bind("<Motion>", self.move_boxes)
def move_boxes(self, event):
print(event.x, event.y)
"""
x, y = (event.x-1, event.y-1)
x1, y1, x2, y2 = self.canvas.bbox("test")
if x > x1 and y > y1 and x < x2 and y < y2:
print("Hit")
else:
print("Missed")
"""
def onNew(self):
new = Node(self, "Node_entry")
label = new.insert_entry_field("Labels")
label2 = new.insert_entry_field("Labels2")
text = new.insert_text_field("Text")
new.ok_cancel_buttons()
def get_info(self):
x, y = (self.size[0]/2, self.size[1]/2)
for i in self.info:
label_frame= LabelFrame(self, text="name")
label_frame.pack(fill="y")
for entry in self.info[i]["Entry"]:
frame = Frame(label_frame)
frame.pack(fill="x")
label = Label(label_frame, text=self.info[i]["Entry"][entry], width=6)
label.pack(side="left", anchor="n", padx=5, pady=5)
for text in self.info[i]["Text"]:
frame = Frame(label_frame)
frame.pack(fill="x")
label = Label(label_frame, text=self.info[i]["Text"][text], width=6)
label.pack(side="left", anchor="n", padx=5, pady=5)
window = self.canvas.create_window(x, y, window=label_frame, tag="test")
开发者ID:Exodus111,项目名称:Projects,代码行数:60,代码来源:main.py
示例9: setUpCanvas
def setUpCanvas():
from tkinter import Tk, Canvas, YES, BOTH
root = Tk()
root.title("A Tk/Python Graphics Program")
canvas = Canvas(root, width = 1270, height = 780, bg = 'black')
canvas.pack(expand = YES, fill = BOTH)
return canvas, root
开发者ID:changarno,项目名称:tjhsst1314,代码行数:7,代码来源:graphics.py
示例10: main
def main():
root = Tk(className="My graphics!")
root.geometry("400x400")
canvas = Canvas()
canvas.pack(fill=BOTH, expand=1)
# img = draw_gradient(canvas)
img = draw_danger_levels(canvas, 50, 50)
# что бы ограничить число
# if n > 255:
# n = 255
# хочу: n = 256 => 0
# n = 257 => 1
# ...
# n = 300 => 44
# 10 // 3 = 3(1)
# 10 - (10 // 3) * 3
# 10 % 3
# a % b < b
# 10 % 3 = 1
# 11 % 3 = 2
# 12 % 3 = 0
# 13 % 3 = 1
root.mainloop()
开发者ID:AndrewLvov,项目名称:DrawTkinter,代码行数:27,代码来源:main.py
示例11: simulation_canvas
def simulation_canvas(parent, **config):
"""Initializes the canvas and sets it up to receive user input."""
global the_canvas
the_canvas = Canvas(parent, **config)
the_canvas.focus_set() # this makes tkinter canvas accept keyboard commands
the_canvas.bind("<Key>", lambda event: model.move_ship(event))
return the_canvas
开发者ID:kishanrajasekhar,项目名称:UFO-Ambush,代码行数:7,代码来源:controller.py
示例12: __init__
def __init__(self, master=None, cnf=None, **kw):
if not cnf:
cnf = {}
Canvas.__init__(self, master, cnf, **kw)
self._polygons = list()
self._layer = None
self._image = None
开发者ID:tobchen,项目名称:LayeredPolygons,代码行数:8,代码来源:view.py
示例13: set_view
def set_view(self, root_view: tk.Canvas=None, _x=0, _y=0):
if isinstance(root_view, tk.Canvas):
self.__Rect = RegionRect(root_view, self.__name, self.__current_price)
self.__Rect.grid(column=_x, row=2*_y)
frame = tk.Frame(root_view, height=38, width=0)
frame.grid(column=_x, row=2*_y+1)
x,y=_x*90, _y*80
root_view.create_rectangle(x,y, x+90, y+80, width=1, fill="white")
开发者ID:KimJae-Woo,项目名称:final_project,代码行数:8,代码来源:region.py
示例14: CameraView
class CameraView(View):
def __init__(self, params):
super(CameraView, self).__init__(params)
self._multiplier = int(params["multiplier"]) if "multiplier" in params else 1
self._multiplier = max(self._multiplier, 1)
self._tk = Tk()
self._canvas = Canvas(self._tk, width=80 * self._multiplier, height=60 * self._multiplier)
self._tk.title("Camera view")
self._tk.resizable(width=False, height=False)
self._canvas.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)
self._tk.protocol("WM_DELETE_WINDOW", self.on_press_close)
self._base_dir = "camera_" + str(int(time.time() * 1000))
os.makedirs(self._base_dir)
def run(self):
super(CameraView, self).run()
self._tk.mainloop()
def on_new_input(self):
try:
hex_str = self.get_input()
img = self._get_image(hex_str)
except Exception as e:
logging.debug(str(e))
return
if img is None:
return
bmp = ImageTk.BitmapImage(image=img, foreground="white", background="black")
self._canvas.create_image(0, 0, image=bmp, anchor=tkinter.NW)
self._tk_image = bmp
img.save(self._base_dir + "/" + str(int(time.time() * 1000)) + ".png")
def on_dismiss(self):
self._tk.after_idle(self.on_press_close)
def on_press_close(self):
self._tk.destroy()
self.join_io_thread()
def _get_image(self, hex_str) -> Image:
try:
hex_data = binascii.unhexlify(hex_str)
# Invert data from MCU
hex_data = bytes([~h & 0xFF for h in hex_data])
except TypeError as e:
logging.debug(str(e))
return
img = Image.frombytes(mode="1", size=(80, 60), data=hex_data)
img = img.resize((80 * self._multiplier, 60 * self._multiplier))
return img
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:58,代码来源:camera_view.py
示例15: __init__
def __init__(self, parent):
"""Simple Canvas class."""
Canvas.__init__(self, parent)
self.parent = parent
self.config(background="white", width=960, height=640)
self.num = 1
self.pack()
self.element_list = []
self.bindings()
开发者ID:Exodus111,项目名称:Projects,代码行数:9,代码来源:stackoverflow.py
示例16: build
def build(self):
width = self.hardware.get('x') * LCD.SCREEN_SCALE
height = self.hardware.get('y') * LCD.SCREEN_SCALE
skin_position = self.hardware.get('skin_position')
if skin_position == 'Y':
width, height = height, width
canvas = Canvas(self.master, width=width, height=height)
canvas.pack()
self.widget = canvas
开发者ID:alej0varas,项目名称:pybolator,代码行数:9,代码来源:pybgui.py
示例17: __init__
def __init__(self, **kwargs):
"""
Constructor
root - reference to the widget containing this widget
"""
Canvas.__init__(self, **kwargs)
self["bg"] = DEAD_COLOUR
GolCell.__init__(self)
开发者ID:richlanc,项目名称:Game_of_life,代码行数:9,代码来源:widgets.py
示例18: main
def main():
root = Tk()
canvas = Canvas(root, bg='white', width=720, height=900)
canvas.pack()
map1 = Map()
map1.drawMap(canvas)
root.mainloop()
开发者ID:greenfox-velox,项目名称:attilakrupl,代码行数:9,代码来源:main.py
示例19: main
def main():
from tkinter import Canvas, mainloop, Tk
gamma, size = [0.3, 0.2, -0.1, -0.4, 0.0], 11
width, height, scale, center = 800, 800, 20, 400+400j
w = Canvas(Tk(), width=width, height=height)
w.pack()
for rhombus, color in tiling(gamma, size):
coords = to_canvas(rhombus, scale, center)
w.create_polygon(*coords, fill=color, outline="black")
mainloop()
开发者ID:mdickinson,项目名称:pentagrid,代码行数:10,代码来源:pentagrid.py
示例20: __init__
def __init__(self, master=None, cnf={}, **kw):
Canvas.__init__(self, master, cnf, **kw)
Observable.__init__(self)
self.__boxId = None
self.__start_x = None
self.__start_y = None
self.bind('<Button-1>', self.onButton1Press)
self.bind('<B1-Motion>', self.onMouseMove)
self.bind('<ButtonRelease-1>', self.onButton1Release)
开发者ID:xialulee,项目名称:WaveSyn,代码行数:10,代码来源:screenshot.py
注:本文中的tkinter.Canvas类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论