屏幕#
简介#
屏幕方法控制 VEX AIR 无人机遥控器如何在屏幕上显示文本、数字、图形和图像,以及如何响应屏幕按键。
以下是可用方法列表:
光标打印 – 显示文本并管理打印光标。
print–在当前光标位置打印文本、数字或变量值。set_cursor–将光标移动到特定的行和列。next_row–将光标移动到下一行的第1列。clear_row–清除一行文本。get_row–返回将打印文本的行。get_column- 返回文本将被打印的一列。
XY 打印 – 根据像素坐标打印文本。
print_at–在特定的x和y坐标处打印文本、数字或变量值。set_origin–设置用于基于坐标的打印和绘图的原点。
修改方法 – 更改屏幕设置、颜色和绘制行为。
clear_screen–清除遥控器屏幕上的所有图形、文本和图像。wait_for_render– 将屏幕绘制切换为稍后渲染行为。set_font–设置打印文本的字体。set_pen_width–设置绘制的线条和形状轮廓的粗细。set_pen_color–设置文本、像素、线条和形状轮廓的颜色。set_text_fill_color- 设置打印文本后的填充颜色。set_fill_color- 设置绘制形状的填充颜色。
绘图——在屏幕上添加图形和图像。
draw_pixel– 在指定的 x 和 y 位置绘制一个像素。draw_line–在两点之间绘制一条线。draw_rectangle– 使用当前画笔和填充颜色绘制矩形。draw_circle– 使用当前画笔和填充颜色绘制一个圆。show_file–绘制上传的图像。
触摸——检测并响应屏幕按压。
pressing–返回当前是否正在按下屏幕。x_position–返回最后一次屏幕按压的x坐标。y_position–返回上一次屏幕按下的y坐标。
回调 – 按下或释放屏幕时运行函数。
光标打印#
print#
print 在遥控器屏幕上的当前光标位置和字体处打印文本、数字或变量值。
用法:
controller.screen.print(text)
参数 |
描述 |
|---|---|
|
要在屏幕上打印的文本、数字或变量值。 |
|
可选。打印文本之间的分隔符。默认情况下, |
|
可选。在最后一个打印文本后追加的字符串。默认情况下, |
|
可选。设置浮点数打印时保留的小数位数,值为整数。默认情况下, |
# Display a message at the starting cursor position.
controller.screen.print("Time to fly!")

# Display the first 2 decimals of pi
controller.screen.print(3.1415, precision = 2)

set_cursor#
set_cursor 将光标移动到遥控器屏幕上指定的行和列。下一次调用 print 时,将从该位置开始打印。行间距和列间距会根据所选字体进行调整。使用默认的中等大小等宽字体时,屏幕最多可清晰显示 18 行和 53 列。超出此范围的文本可能会被截断或难以阅读。
用法:
controller.screen.set_cursor(row, col)
参数 |
描述 |
|---|---|
|
要将光标移动到的行。 |
|
要将光标移动到的列。 |
# Display text starting at Row 7 Column 25.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print("Row 7, Column 25")

next_row#
next_row 将光标移动到控制器屏幕上下一行的第 1 列。
用法:
controller.screen.next_row()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display two lines of text.
controller.screen.print("Line 1")
controller.screen.next_row()
controller.screen.print("Line 2")

clear_row#
clear_row 清除控制器屏幕上的一行文本。
用法:controller.screen.clear_row(row, color)
参数 |
描述 |
|---|---|
|
可选。要清除的行。默认值为当前光标所在行。 |
|
可选。应用于已清除行的颜色。如果未指定颜色,则使用
|
# Clear only the second row of text
controller.screen.print("This text stays")
controller.screen.next_row()
controller.screen.print("This text disappears")
wait(3, SECONDS)
controller.screen.clear_row(2)
# Turn the 5th row green.
controller.screen.clear_row(5, GREEN)
get_row#
get_row 返回文本将打印为整数的当前行。
用法:
controller.screen.get_row()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the cursor's current row.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_row())

get_column#
get_column 返回文本将打印为整数的当前列。
用法:
controller.screen.get_column()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display the cursor's current column.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_column())

XY打印#
print_at#
print_at 使用当前的 字体 和 原点,在遥控器屏幕上指定的像素坐标 (x, y) 位置打印文本、数字或变量值。x 设置文本起始位置距离屏幕左侧的距离,y 设置文字底部所在的位置。此方法不受当前光标位置的影响。
用法:
controller.screen.print_at(text, x, y)
参数 |
描述 |
|---|---|
|
要在屏幕上打印的文本、数字或变量值。 |
|
文本的水平位置,以 0 到 640 像素之间的整数表示。0 为左;640 为右。 |
|
文本的垂直位置,以 0 到 480 像素之间的整数表示。0 表示顶部;480 表示底部。 |
# Display a message in the middle of the screen.
controller.screen.print_at("Hello, drone!", x=320, y=240)

set_origin#
set_origin 设置用于在遥控器屏幕上绘图和基于坐标打印的原点 (0, 0)。默认情况下,原点位于屏幕左上角。此方法可以将原点重新设置为屏幕上其他指定的 (x, y) 坐标位置。
用法:
controller.screen.set_origin(x, y)
参数 |
描述 |
|---|---|
|
设置为原点的新 x 坐标,以 0 到 640 之间的整数形式给出。 |
|
设置为原点的新 y 坐标,以 0 到 480 之间的整数形式给出。 |
# Set the origin to the center of the screen.
controller.screen.set_origin(x=320, y=240)
# Draw a rectangle at the new origin.
controller.screen.draw_rectangle(x=0, y=0, width=80, height=40)

修改方法#
clear_screen#
clear_screen 将清除遥控器屏幕中的所有图形、文本和图像。
用法:
controller.screen.clear_screen(row, col, color)
参数 |
描述 |
|---|---|
|
可选。清除屏幕后光标移动到的行。默认值为 1。 |
|
可选。清除屏幕后光标移动到的列。默认值为 1。 |
|
可选。设置屏幕颜色。如果包含
|
# Draw a circle, and clear it after 2 seconds.
controller.screen.draw_circle(x=320, y=240, radius=80)
wait(2, SECONDS)
controller.screen.clear_screen()
# Print two messages in the same spot
controller.screen.print("Hello!")
wait(3,SECONDS)
controller.screen.clear_screen(row=1, col=1)
controller.screen.print("Goodbye!")
# Set the background color of the screen to red.
controller.screen.clear_screen(color=RED)
wait_for_render#
wait_for_render 将屏幕绘制切换为延迟渲染模式。执行此方法后,后续的屏幕绘制命令不会立即显示在遥控器屏幕上,直到下一次执行 wait_for_render 方法。
注意: 在绘制一组文本、形状或图像之前使用此方法,然后再次使用此方法可一次性渲染完整的更新。
用法:
controller.screen.wait_for_render()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display text and images when button 7 is pressed.
controller.screen.wait_for_render()
controller.screen.print("Screen rendered!")
controller.screen.draw_circle(x=320, y=240, radius=80)
while not controller.button7.pressing():
wait(5, MSEC)
controller.screen.wait_for_render()

set_font#
set_font 设置用于在遥控器屏幕上显示文本的字体。执行此方法后打印的所有文本都将使用该字体。项目开始时的默认字体为 MONO20。
用法:
controller.screen.set_font(fontname)
参数 |
描述 |
|---|---|
|
将字体设置为以下选项之一:
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
# Display text using a larger font.
controller.screen.set_font(MONO40)
controller.screen.print("VEX")

set_pen_width#
set_pen_width 设置绘制的线条和形状轮廓的厚度。
用法:
controller.screen.set_pen_width(width)
参数 |
描述 |
|---|---|
|
笔的宽度,以像素为单位的整数表示。 |
# Draw a rectangle with a pen width of 10.
controller.screen.set_pen_width(10)
controller.screen.draw_rectangle(x=200, y=200, width=200, height=80)

set_pen_color#
set_pen_color 设置文本、像素、线条和形状轮廓的颜色。
用法:
controller.screen.set_pen_color(color)
参数 |
描述 |
|---|---|
|
可选。设置画笔和字体颜色。可选颜色包括:
|
# Draw a rectangle with an orange outline.
controller.screen.set_pen_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=240, height=150)
controller.screen.set_pen_color(WHITE)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

set_text_fill_color#
set_text_fill_color 设置打印文本的背景填充颜色。默认文本填充颜色为透明。
用法:
controller.screen.set_text_fill_color(color)
参数 |
描述 |
|---|---|
|
可选。设置文本填充颜色。可选颜色包括:
|
# Display two colors behind text
controller.screen.set_text_fill_color(RED)
controller.screen.print("Red")
controller.screen.next_row()
controller.screen.set_text_fill_color(BLUE)
controller.screen.print("Blue")

set_fill_color#
set_fill_color 设置绘制形状时使用的填充颜色。默认填充颜色为黑色。
用法:
controller.screen.set_fill_color(color)
参数 |
描述 |
|---|---|
|
可选。设置填充颜色。可选颜色包括:
|
# Draw an orange-filled rectangle with text on top
controller.screen.set_fill_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=250, height=150)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

绘制#
draw_pixel#
draw_pixel 使用当前笔颜色在所选x和y坐标处绘制一个像素。
用法:
controller.screen.draw_pixel(x, y)
参数 |
描述 |
|---|---|
|
将绘制像素的 x 坐标,以 0 到 640 之间的整数表示。 |
|
将绘制像素的 y 坐标,以 0 到 480 之间的整数表示。 |
# Draw five pixels in a diagonal.
controller.screen.draw_pixel(x=360, y=200)
controller.screen.draw_pixel(x=340, y=220)
controller.screen.draw_pixel(x=320, y=240)
controller.screen.draw_pixel(x=300, y=260)
controller.screen.draw_pixel(x=280, y=280)
![]()
draw_line#
draw_line 使用当前的笔宽和笔颜色,从第一个屏幕坐标 (x1, y1) 到第二个屏幕坐标 (x2, y2) 绘制一条直线。
除非已使用 set_origin 设置了不同的原点,否则 x 和 y 坐标使用默认原点 (0, 0)。
用法:
controller.screen.draw_line(x1, y1, x2, y2)
参数 |
描述 |
|---|---|
|
线的起始 x 坐标,以 0 到 640 之间的整数表示。 |
|
线的起始 y 坐标,以 0 到 480 之间的整数表示。 |
|
线的结束 x 坐标,以 0 到 640 之间的整数表示。 |
|
线的结束 y 坐标,以 0 到 480 之间的整数表示。 |
# Make an X across the screen.
controller.screen.draw_line(x1=0, y1=0, x2=640, y2=480)
controller.screen.set_pen_color(CYAN)
controller.screen.draw_line(x1=0, y1=480, x2=640, y2=0)

draw_rectangle#
draw_rectangle 使用当前的 画笔宽度、画笔颜色 和 填充颜色 绘制矩形,除非使用可选的 color 参数。
除非已使用 set_origin 设置了不同的原点,否则 x 和 y 坐标使用默认原点 (0, 0)。
用法:
controller.screen.draw_rectangle(x, y, width, height, color)
参数 |
描述 |
|---|---|
|
矩形左上角的 x 坐标,以 0 到 640 之间的整数表示。 |
|
矩形左上角的 y 坐标,以 0 到 480 之间的整数表示。 |
|
矩形的宽度,以 0 到 640 之间的整数表示。 |
|
矩形的高度,以 0 到 480 之间的整数表示。 |
|
可选。设置矩形的填充颜色。可选颜色包括:
|
# Draw two rectangles on the screen.
controller.screen.draw_rectangle(x=0, y=0, width=620, height=460)
controller.screen.draw_rectangle(x=200, y=180, width=200, height=100, color=GREEN)

draw_circle#
draw_circle 使用当前的 画笔宽度、画笔颜色 和 填充颜色 绘制圆形,除非使用可选的 color 参数。
除非已使用 set_origin 设置了不同的原点,否则 x 和 y 坐标使用默认原点 (0, 0)。
用法:
controller.screen.draw_circle(x, y, radius, color)
参数 |
描述 |
|---|---|
|
圆心的 x 坐标,以 0 到 640 之间的整数表示。 |
|
圆心的 y 坐标,以 0 到 480 之间的整数表示。 |
|
圆的半径,以 0 到 480 像素之间的整数表示。 |
|
可选。设置圆形的填充颜色。可选颜色包括:
|
# Draw one green circle on the screen.
controller.screen.set_fill_color(GREEN)
controller.screen.draw_circle(x=320, y=240, radius=200, color=GREEN)

show_file#
show_file 在遥控器屏幕上的指定 x 和 y 坐标位置绘制自定义上传的图像,并可选择进行缩放、旋转和设置 Alpha 透明度。
用法:
controller.screen.show_file(file, x, y, scale_width, scale_height, rotation, use_alpha)
参数 |
描述 |
|---|---|
|
要使用的用户上传的图片。如果在控制面板中编辑了图片名称,选项将会更改。 |
|
图像的水平偏移量,以像素为单位的整数形式指定。正值表示向右移动;负值表示向左移动。 |
|
图像的垂直偏移量,以像素为单位的整数形式指定。正值表示向下移动;负值表示向上移动。 |
|
可选。要缩放的图像宽度,以像素为单位的整数形式给出。 |
|
可选。要缩放的图像高度,以像素为单位的整数形式给出。 |
|
可选参数。图像旋转的角度,取值范围为 0 到 359 之间的整数。 |
|
可选。是否使用图像的 Alpha 通道实现透明效果。可选值包括: |
# Display uploaded Image 1 in the top left corner.
controller.screen.show_file(IMAGE1, x=0, y=0)
# Display uploaded Image 1 scaled to the full screen.
controller.screen.show_file(IMAGE1, x=65, y=0, scale_width=640, scale_height=480)
# Display uploaded Image 1 with rotation of 180 degrees.
controller.screen.show_file(IMAGE1, x=-65, y=0, rotation=180)
# Upload an image with a transparent background.
# Display uploaded Image 1 with alpha channel enabled.
controller.screen.show_file(IMAGE1, x=0, y=0, use_alpha=True)
触碰#
pressing#
pressing 返回一个布尔值,指示当前是否正在按下机器人的屏幕。
True–正在按下屏幕。False–未按下屏幕。
用法:
controller.screen.pressing()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Play a sound when the screen is pressed.
while True:
if controller.screen.pressing():
controller.sound.play_note("C5", 500)
wait(5, MSEC)
# Display different messages after the screen is pressed
while not controller.screen.pressing():
wait(5, MSEC)
controller.screen.print("First message!")
controller.screen.next_row()
# Lift finger to press the screen again
while controller.screen.pressing():
wait(5, MSEC)
while not controller.screen.pressing():
wait(5, MSEC)
controller.screen.print("Second message!")
controller.screen.next_row()
x_position#
x_position 返回屏幕上次被按下位置的 x 坐标(以像素为单位),返回值为 0(左侧)到 640(右侧)之间的整数。

用法:
controller.screen.x_position()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Play a high or low note based on where screen is pressed.
while True:
if controller.screen.pressing():
if controller.screen.x_position() > 320:
controller.sound.play_note("C6", 500)
else:
controller.sound.play_note("C4", 500)
wait(5, MSEC)
y_position#
y_position 返回屏幕上次被按下位置的 y 坐标(以像素为单位),返回值为 0(顶部)到 480(底部)之间的整数。

用法:
controller.screen.y_position()
# Play a high or low note based on where screen is pressed.
while True:
if controller.screen.pressing():
if controller.screen.y_position() > 240:
controller.sound.play_note("C6", 500)
else:
controller.sound.play_note("C4", 500)
wait(5, MSEC)
回调函数#
pressed#
pressed 注册一个在遥控器屏幕被按下时调用的函数。
用法:
controller.screen.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
一个预先定义好的函数,当按下遥控器屏幕时执行。 |
|
# Play a sound when the screen is pressed.
def play_sound():
controller.sound.play_note("C5", 500)
controller.screen.pressed(play_sound)
released#
released 注册一个在遥控器屏幕被释放时调用的函数。
用法:
controller.screen.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的一个函数,当遥控器屏幕释放时执行。 |
|
# Play a sound when the screen is pressed.
def play_sound():
controller.sound.play_note("C5", 500)
controller.screen.released(play_sound)













