本文整理汇总了Python中tkinter.Canvas.bind_all方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.bind_all方法的具体用法?Python Canvas.bind_all怎么用?Python Canvas.bind_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.bind_all方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Canvas
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bind_all [as 别名]
global dn
global times
global correct
global direcs
global totalresp
global top
global curd
correct = []
times = []
direcs = []
totalresp = 0
top = tkinter.Tk()
gameboard = Canvas(top, bg = "black", width = 1000, height = 750)
downI = PhotoImage(file = "Down.PNG")
upI = PhotoImage(file = "Up.PNG")
leftI = PhotoImage(file = "Left.PNG")
rightI = PhotoImage(file = "Right.PNG")
cur = 1
curd = 1
dn = 0
arrow = gameboard.create_image(650, 200, anchor= "ne", image = downI)
tdisp = gameboard.create_text(0, 0, anchor = "ne", text = '', fill = 'red')
gameboard.pack()
gameboard.bind_all('<KeyRelease>', kp)
start = time.time()
top.mainloop()
示例2: text_canvas
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bind_all [as 别名]
#.........这里部分代码省略.........
def draw_line_numbers(
self, start,
highlightcolor=options['line_num_highlight_color'],
textcolor=options['line_num_text_color']
):
self.canvas.create_rectangle(
0, 0, self.line_num_spacing / 2,
self.winfo_screenheight(),
fill=highlightcolor, outline=highlightcolor
)
for i in range(self.line_height + 1):
self.canvas.create_text(
0, self.cheight * i + (i * 2), anchor='nw',
text=str(start + i), font=self.text_font,
fill=textcolor
)
def draw_cursor(
self, x, y,
highlightcolor=options['cursor_highlight_color'],
cursorcolor=options['cursor_color']
):
"""
draw cursor as well as line and column highlights
TODO: users should have the option to disable line
and column highlights
"""
x_val = self.cwidth * x + self.line_num_spacing
y_val = self.cheight * y + (y * 2)
self.canvas.create_rectangle(
0, y_val, self.winfo_screenwidth(),
y_val + self.cheight + 4,
fill=highlightcolor, outline=highlightcolor
)
self.canvas.create_rectangle(
x_val, 0, x_val + self.cwidth,
self.winfo_screenheight(), fill=highlightcolor,
outline=highlightcolor
)
self.canvas.create_rectangle(
x_val, y_val, x_val + self.cwidth,
y_val + self.cheight + 4,
fill=cursorcolor, outline=cursorcolor
)
def draw_rectangle_absolute(
self, x1, y1, x2, y2, color
):
"""
draw rectangle onto screen
TODO: flesh out what this function should actually
look like
"""
self.canvas.create_rectangle(
x1, y1, x2, y2,
fill=color, outline=color
)
def bind_events(self, input_handler):
"""
bind events for use in input_handler
TODO: this should be cleaned up ideally into a separate handler list
"""
input_handler.set_GUI_reference(self)
self.canvas.bind('<Key>', input_handler.key)
self.canvas.bind_all('<Escape>', input_handler.escape)
self.canvas.bind_all('<Control-a>', input_handler.control_a)
self.canvas.bind_all('<Control-b>', input_handler.control_b)
self.canvas.bind_all('<Control-c>', input_handler.control_c)
self.canvas.bind_all('<Control-d>', input_handler.control_d)
self.canvas.bind_all('<Control-e>', input_handler.control_e)
self.canvas.bind_all('<Control-f>', input_handler.control_f)
self.canvas.bind_all('<Control-g>', input_handler.control_g)
self.canvas.bind_all('<Control-h>', input_handler.control_h)
self.canvas.bind_all('<Control-i>', input_handler.control_i)
self.canvas.bind_all('<Control-j>', input_handler.control_j)
self.canvas.bind_all('<Control-k>', input_handler.control_k)
self.canvas.bind_all('<Control-l>', input_handler.control_l)
self.canvas.bind_all('<Control-m>', input_handler.control_m)
self.canvas.bind_all('<Control-n>', input_handler.control_n)
self.canvas.bind_all('<Control-o>', input_handler.control_o)
self.canvas.bind_all('<Control-p>', input_handler.control_p)
self.canvas.bind_all('<Control-q>', input_handler.control_q)
self.canvas.bind_all('<Control-r>', input_handler.control_r)
self.canvas.bind_all('<Control-s>', input_handler.control_s)
self.canvas.bind_all('<Control-t>', input_handler.control_t)
self.canvas.bind_all('<Control-u>', input_handler.control_u)
self.canvas.bind_all('<Control-v>', input_handler.control_v)
self.canvas.bind_all('<Control-w>', input_handler.control_w)
self.canvas.bind_all('<Control-x>', input_handler.control_x)
self.canvas.bind_all('<Control-y>', input_handler.control_y)
self.canvas.bind_all('<Control-z>', input_handler.control_z)
self.canvas.bind_all("<MouseWheel>", input_handler.mouse_scroll)
self.canvas.bind_all(
'<Control-braceright>', input_handler.control_braceright
)
self.canvas.bind_all(
'<Control-braceleft>', input_handler.control_braceleft
)
示例3: Body
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bind_all [as 别名]
rocket = Body(canvas, 5, [478.0, 9000.0], '#fafabb')
planet = Body(canvas, 2*10**17, [0.0, 9000.0], 'blue')
planet2 = Body(canvas, 2*10**17, [0.0, -9000.0], 'red')
star = Body(canvas, 1*10**19, [0.0, 0.0], 'yellow')
rocket_icon = Icon(canvas, rocket, 'black')
star_icon = Icon(canvas, star, 'yellow')
planet_icon = Icon(canvas, planet, 'blue')
planet2_icon = Icon(canvas, planet2, 'red')
icons_dict = {rocket: rocket_icon, star: star_icon, planet2: planet2_icon, planet: planet_icon}
bodies = [planet, star, planet2, rocket]
init_vel_dict = {planet: [190.0, 0.0], star: [0.0, 0.0], planet2: [-190.0, 0.0], rocket: [190, 0.0]}
dt = 0.01
mainbody = rocket
centered_body = rocket
canvas.bind_all('<KeyPress-Up>', mainbody.go_down)
canvas.bind_all('<KeyPress-Down>', mainbody.go_up)
canvas.bind_all('<KeyPress-Left>', mainbody.go_left)
canvas.bind_all('<KeyPress-Right>', mainbody.go_right)
canvas.bind_all('<space>', mainbody.launch)
for x in range(20):
for y in range(20):
canvasicon.create_rectangle(x*15, y*15, (x + 1)*15, (y + 1)*15)
while True:
contact(bodies, mainbody)
fast(bodies, mainbody)
if contact_bool == False and crash == False:
for eachbod in bodies: